/// <summary> /// 关闭UI 单例的隐藏 非单例的销毁 /// </summary> public static void Close<T>() where T : MFUIBase { if (!IsBind<T>()) return; Type uiScript = typeof(T); UIBindInfo uiInfo = _uiInfobDic[uiScript]; GameObject uiObj = _aliveUI[uiScript]; uiObj.GetComponent<T>().Invoke("OnClose", 0); if (uiInfo.instType == UIInstanceType.single) { uiObj.SetActive(false); } else { _aliveUI.Remove(uiScript); GameObject.Destroy(uiObj); } }
/// <summary> /// 将UI脚本组件与Prefab绑定 /// </summary> public static void BindPrefab<T>(string prefabPath, UILayer layer, UIInstanceType instType) where T : MFUIBase { Type uiScript = typeof(T); GameObject uiPrefab = MFResoureUtil.LoadPrefabFromPath(prefabPath); Assert.IsNotNull(uiPrefab); UIBindInfo info = new UIBindInfo { prefab = uiPrefab, layer = layer, instType = instType, }; if (_uiInfobDic.ContainsKey(uiScript)) { MFLog.LogError("UI脚本重复绑定!!!"); } _uiInfobDic.Add(uiScript, info); }
private static void CreateNewUI<T>(Action<T> action = null) where T : MFUIBase { Type uiScript = typeof(T); UIBindInfo uiInfo = _uiInfobDic[uiScript]; GameObject uiObj = GameObject.Instantiate(uiInfo.prefab); Transform parent = _mainUILayer.transform; // default switch (uiInfo.layer) { case UILayer.main: parent = _mainUILayer.transform; break; case UILayer.fight: break; } uiObj.transform.SetParent(parent, false); _aliveUI.Add(uiScript, uiObj); Show<T>(action); }