/// <summary> /// 利用挂载特性的泛型对象异步加载Prefab; /// 泛型对象为Mono类型; /// </summary> /// <typeparam name="T">非Mono对象</typeparam> /// <param name="callBack">加载完毕后的回调</param> internal void LoadResPrefabInstanceAsync <T>(Action <T, GameObject> callBack = null) where T : class, IReference, new() { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); if (attribute != null) { Facade.StartCoroutine(EnumLoadResPrefabInstanceAsync <T>(attribute.ResourcePath, callBack)); } }
/// <summary> /// 利用挂载特性的泛型对象异步加载Prefab; /// </summary> /// <typeparam name="T">组件类型</typeparam> /// <param name="callBack">载入完毕后的回调</param> internal void LoadResPrefabAsync <T>(Action <T> callBack = null) where T : MonoBehaviour { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); if (attribute != null) { Facade.StartCoroutine(EnumLoadResPrefabAsync <T>(attribute.ResourcePath, callBack)); } }
internal void RemovePanel <T>() where T : UILogicBase { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); if (attribute == null) { return; } if (uiPanelDict.ContainsKey(attribute.PrefabName)) { var result = uiPanelDict[attribute.PrefabName].gameObject; GameManager.KillObject(result); uiPanelDict.Remove(attribute.PrefabName); } else { Utility.Debug.LogError("UIManager-->>" + "Panel :" + attribute.PrefabName + " not register !"); } }
/// <summary> /// 利用挂载特性的泛型对象同步加载Prefab; /// </summary> /// <typeparam name="T">需要加载的类型</typeparam> /// <param name="instantiate">是否生实例化对象</param> /// <returns>返回实体化或未实例化的资源对象</returns> internal GameObject LoadResPrefab <T>(bool instantiate = false) where T : MonoBehaviour { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); GameObject prefab = default; if (attribute != null) { prefab = Resources.Load <GameObject>(attribute.ResourcePath); if (prefab == null) { throw new ArgumentNullException("ResourceManager-->>" + "Assets: " + attribute.ResourcePath + " not exist,check your path!"); } if (instantiate) { prefab = Utility.Unity.Instantiate <T>(prefab).gameObject; } } return(prefab); }
/// <summary> /// 通过特性UIResourceAttribute加载Panel /// </summary> /// <typeparam name="T"></typeparam> /// <param name="callBack"></param> internal void ShowPanel <T>(Action <T> callBack = null) where T : UILogicBase { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); if (attribute == null) { return; } if (HasPanel(attribute.PrefabName)) { callBack?.Invoke(uiPanelDict[attribute.PrefabName] as T); return; } Facade.LoadResPrefabAsync <T>(panel => { panel.transform.SetParent(MainUICanvas.transform); (panel.transform as RectTransform).ResetLocalTransform(); callBack?.Invoke(panel); uiPanelDict.Add(attribute.PrefabName, panel); }); }
/// <summary> /// 利用挂载特性的泛型对象同步加载PrefabObject; /// </summary> /// <typeparam name="T">实现了引用池的非Mono对象</typeparam> /// <param name="go">载入的资源对象</param> /// <param name="instantiate">是否实例化</param> /// <returns>载入的对象</returns> internal GameObject LoadResPrefabInstance <T>(bool instantiate = false) where T : class, IReference, new() { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); GameObject go = default; T referObj = default; if (attribute != null) { go = Resources.Load <GameObject>(attribute.ResourcePath); if (go == null) { throw new ArgumentNullException("ResourceManager-->>" + "Assets: " + attribute.ResourcePath + " not exist,check your path!"); } referObj = Facade.SpawnReference <T>(); if (instantiate) { go = GameObject.Instantiate(go); } } return(go); }
/// <summary> /// 通过特性UIResourceAttribute加载Panel /// </summary> /// <typeparam name="T">UILogicBase派生类</typeparam> /// <param name="callBack">加载完毕后的回调</param> internal void LoadPanel <T>(Action <T> callBack = null) where T : UILogicBase { Type type = typeof(T); PrefabUnitAttribute attribute = type.GetCustomAttribute <PrefabUnitAttribute>(); if (attribute == null) { return; } if (HasPanel(attribute.PrefabName)) { return; } Facade.LoadResPrefabAsync <T>(go => { go.transform.SetParent(MainUICanvas.transform); (go.transform as RectTransform).ResetLocalTransform(); go.gameObject.name = attribute.PrefabName; callBack?.Invoke(go); uiPanelDict.Add(attribute.PrefabName, go); } ); }