using System.Collections; using System.Collections.Generic; using UnityEngine; using HJDFrameWork; public class ItemManager : MonoSingleton { [Header("已注册物体类")] public List _registerList = new List(); private Dictionary ItemDict = new Dictionary(); public void Init() { //查找->初始化 ItemSign[] items = GameObject.FindObjectsOfType(); for (int i = 0; i < items.Length; i++) { items[i].Init(); } } public void Register(string itemName, ItemSign item) { if (!ItemDict.ContainsKey(itemName)) { ItemDict.Add(itemName, item); _registerList.Add(itemName); Debug.Log(itemName + "注册成功"); } else { Debug.Log(itemName + "已注册,请勿重复注册"); } } public ItemSign GetItem(string itemName) { ItemSign item= null; if (ItemDict.TryGetValue(itemName, out item)) { return item; } else { Debug.LogError(itemName + "获取失败!"); return null; } } }