| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public class ItemToggleFactory : ScriptableObject |
| | 5 | | { |
| | 6 | | [System.Serializable] |
| | 7 | | public class NftMap |
| | 8 | | { |
| | 9 | | public string rarity; |
| | 10 | | public ItemToggle prefab; |
| | 11 | | } |
| | 12 | |
|
| | 13 | | public ItemToggle baseWearable; |
| | 14 | | public NftMap[] nftList; |
| | 15 | |
|
| | 16 | | internal Dictionary<string, NftMap> nftDictionary; |
| | 17 | |
|
| | 18 | | public void EnsureNFTDictionary() |
| | 19 | | { |
| 36 | 20 | | if (nftDictionary == null) |
| | 21 | | { |
| 1 | 22 | | nftDictionary = new Dictionary<string, NftMap>(); |
| | 23 | |
|
| 16 | 24 | | for (int i = 0; i < nftList.Length; i++) |
| | 25 | | { |
| 7 | 26 | | NftMap nftMap = nftList[i]; |
| | 27 | |
|
| 7 | 28 | | if (!nftDictionary.ContainsKey(nftMap.rarity)) |
| | 29 | | { |
| 7 | 30 | | nftDictionary.Add(nftMap.rarity, nftMap); |
| | 31 | | } |
| | 32 | | } |
| | 33 | | } |
| 36 | 34 | | } |
| | 35 | |
|
| 4032 | 36 | | public ItemToggle CreateBaseWearable(Transform parent = null) { return parent == null ? Instantiate(baseWearable) : |
| | 37 | |
|
| | 38 | | public ItemToggle CreateItemToggleFromRarity(string rarity, Transform parent = null) |
| | 39 | | { |
| 36 | 40 | | EnsureNFTDictionary(); |
| | 41 | |
|
| 36 | 42 | | if (!nftDictionary.ContainsKey(rarity)) |
| | 43 | | { |
| | 44 | | #if UNITY_EDITOR |
| 0 | 45 | | Debug.LogError("Item toggle of rarity " + rarity + " can't be instantiated because it does not exist in the |
| | 46 | | #endif |
| 0 | 47 | | return CreateBaseWearable(parent); |
| | 48 | | } |
| | 49 | |
|
| 36 | 50 | | if (nftDictionary[rarity].prefab == null) |
| | 51 | | { |
| 0 | 52 | | Debug.LogError("Prefab for rarity " + rarity + " is null!"); |
| 0 | 53 | | return CreateBaseWearable(parent); |
| | 54 | | } |
| | 55 | |
|
| 36 | 56 | | return parent == null ? Instantiate(nftDictionary[rarity].prefab) : Instantiate(nftDictionary[rarity].prefab, pa |
| | 57 | | } |
| | 58 | | } |