You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using HJDFrameWork;
|
|
|
|
public class ItemManager : MonoSingleton<ItemManager>
|
|
{
|
|
[Header("已注册物体类")]
|
|
public List<string> _registerList = new List<string>();
|
|
|
|
private Dictionary<string, ItemSign> ItemDict = new Dictionary<string, ItemSign>();
|
|
|
|
public void Init()
|
|
{
|
|
//查找->初始化
|
|
ItemSign[] items = GameObject.FindObjectsOfType<ItemSign>();
|
|
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;
|
|
}
|
|
}
|
|
}
|