| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | [CreateAssetMenu(fileName = "StickersFactory", menuName = "Variables/StickersFactory")] |
| | 6 | | public class StickersFactory : ScriptableObject |
| | 7 | | { |
| | 8 | | [Serializable] |
| | 9 | | public class StickerFactoryEntry |
| | 10 | | { |
| | 11 | | public string id; |
| | 12 | | public GameObject stickerPrefab; |
| | 13 | | } |
| | 14 | |
|
| 1 | 15 | | [SerializeField] private List<StickerFactoryEntry> stickersList = new List<StickerFactoryEntry>(); |
| | 16 | | private Dictionary<string, GameObject> stickers; |
| | 17 | |
|
| | 18 | | private void EnsureDict() |
| | 19 | | { |
| 54 | 20 | | if (stickers != null) |
| 53 | 21 | | return; |
| | 22 | |
|
| 1 | 23 | | stickers = new Dictionary<string, GameObject>(); |
| 18 | 24 | | for (int i = 0; i < stickersList.Count; i++) |
| | 25 | | { |
| 8 | 26 | | stickers.Add(stickersList[i].id, stickersList[i].stickerPrefab); |
| | 27 | | } |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | | public bool TryGet(string id, out GameObject stickerPrefab) |
| | 31 | | { |
| 54 | 32 | | EnsureDict(); |
| | 33 | |
|
| 54 | 34 | | return stickers.TryGetValue(id, out stickerPrefab); |
| | 35 | | } |
| | 36 | | } |