using System.Collections.Generic; using UnityEngine; namespace TyphoonUI { /// /// UI资源包 /// [CreateAssetMenu(menuName = "TyphoonUI/UI Package")] public class UIPackage : ScriptableObject { [HideInInspector] //组件 public List Components = new List(); private Dictionary _map = null; public Dictionary Map { get { if (_map == null) { _map = GetSourcesMap(); } return _map; } } #if UNITY_EDITOR public List ObjectsOfPacking = new List(); //错误信息 [HideInInspector] public string ErrorString = ""; #endif /// /// 获取资源Map /// public Dictionary GetSourcesMap() { var dic = new Dictionary(); foreach (var component in Components) { dic.Add(component.name, component); } return dic; } /// /// 获取资源 /// public GameObject Get(string sourceName) { return Map[sourceName]; } /// /// 是否有资源 /// public bool Has(string sourceName) { return Map.ContainsKey(sourceName); } /// /// 尝试获取资源 /// public bool TryGet(string sourceName, out GameObject match) { return Map.TryGetValue(sourceName, out match); } } }