Added new fruit prefabs
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using Unity.Plastic.Antlr3.Runtime.Tree;
|
||||
|
||||
namespace Fruitomation.Game.Items
|
||||
{
|
||||
public class ItemInfoRegistry : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private SerializedItemInfoRegistry SerializedRegistry;
|
||||
|
||||
[Header("References")] [SerializeField]
|
||||
private SerializedItemInfoRegistry SerializedRegistry;
|
||||
|
||||
private Dictionary<ItemType, ItemInfo> Dictionary;
|
||||
private static ItemInfoRegistry Instance;
|
||||
|
||||
@@ -34,22 +35,31 @@ namespace Fruitomation.Game.Items
|
||||
}
|
||||
}
|
||||
|
||||
[InspectorCallable("Load Registry")] private void LoadFromRegistry()
|
||||
[InspectorCallable("Load Registry")]
|
||||
private void LoadFromRegistry()
|
||||
{
|
||||
Dictionary = new Dictionary<ItemType, ItemInfo>();
|
||||
foreach (ItemInfo info in SerializedRegistry.Registry)
|
||||
{
|
||||
Dictionary.Add(info.Type, info);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
ItemType[] types = Enum.GetValues(typeof(ItemType)) as ItemType[];
|
||||
Debug.Assert(types != null, nameof(types) + " != null");
|
||||
|
||||
|
||||
foreach (ItemType type in types)
|
||||
{
|
||||
bool contained = Dictionary.ContainsKey(type);
|
||||
if (!contained)
|
||||
if (type == ItemType.None)
|
||||
{
|
||||
if (contained)
|
||||
{
|
||||
Debug.LogError("ItemType.None should not be included in ItemInfoRegistry");
|
||||
}
|
||||
}
|
||||
|
||||
else if (!contained)
|
||||
{
|
||||
Debug.LogWarning($"Type [{type}] is not contained in the registry");
|
||||
}
|
||||
@@ -57,6 +67,15 @@ namespace Fruitomation.Game.Items
|
||||
#endif // UNITY_EDITOR
|
||||
}
|
||||
|
||||
public static ItemInfo Get(ItemType type) => Instance.Dictionary[type];
|
||||
public static ItemInfo Get(ItemType type)
|
||||
{
|
||||
if (type == ItemType.None)
|
||||
{
|
||||
Debug.LogError("ItemType.None is not a valid ItemType value for ItemInfoRegistry.Get");
|
||||
return null;
|
||||
}
|
||||
|
||||
return Instance.Dictionary[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user