| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class NFTSkinFactory : ScriptableObject |
| | 6 | | { |
| | 7 | | [System.Serializable] |
| | 8 | | public class NftMap |
| | 9 | | { |
| | 10 | | public string rarity; |
| | 11 | | public NFTItemToggleSkin skin; |
| | 12 | | } |
| | 13 | |
|
| | 14 | | public NftMap[] nftList; |
| | 15 | |
|
| | 16 | | internal Dictionary<string, NftMap> nftDictionary; |
| | 17 | |
|
| | 18 | | public void EnsureNFTDictionary() |
| | 19 | | { |
| 6447 | 20 | | if (nftDictionary == null) |
| | 21 | | { |
| 1 | 22 | | nftDictionary = new Dictionary<string, NftMap>(); |
| | 23 | |
|
| 18 | 24 | | for (int i = 0; i < nftList.Length; i++) |
| | 25 | | { |
| 8 | 26 | | NftMap nftMap = nftList[i]; |
| | 27 | |
|
| 8 | 28 | | if (!nftDictionary.ContainsKey(nftMap.rarity)) |
| | 29 | | { |
| 8 | 30 | | nftDictionary.Add(nftMap.rarity, nftMap); |
| | 31 | | } |
| | 32 | | } |
| | 33 | | } |
| 6447 | 34 | | } |
| | 35 | |
|
| | 36 | | public NFTItemToggleSkin GetSkinForRarity(string rarity) |
| | 37 | | { |
| 6447 | 38 | | EnsureNFTDictionary(); |
| | 39 | |
|
| 6447 | 40 | | if (string.IsNullOrEmpty(rarity)) |
| 6348 | 41 | | return nftDictionary["base"].skin; |
| | 42 | |
|
| 99 | 43 | | if (!nftDictionary.ContainsKey(rarity)) |
| 0 | 44 | | return nftDictionary["base"].skin; |
| | 45 | |
|
| 99 | 46 | | return nftDictionary[rarity].skin; |
| | 47 | | } |
| | 48 | | } |