/// <summary> /// 销毁窗口 /// </summary> /// <param name="obj"></param> private void DestroyWindow(UIWindowViewBase windowBase) { m_DicWindow.Remove(windowBase.CurrentUIType); Object.Destroy(windowBase.gameObject); }
//public void LoadWindowForLua(string viewName, XLuaCustomExport.OnCreate OnCreate = null, string path = null) //{ // LoadWindow(viewName, null, null, OnCreate, path); //} //public void LoadWindow(string viewName, Action<GameObject> onComplete, Action OnShow = null, XLuaCustomExport.OnCreate OnCreate = null, string path = null) public void LoadWindow(string viewName, Action <GameObject> onComplete, Action OnShow = null, string path = null) { if (!m_DicWindow.ContainsKey(viewName) || m_DicWindow[viewName] == null) { string newPath = string.Empty; if (string.IsNullOrEmpty(path)) { newPath = string.Format("Download/Prefab/UIPrefab/UIWindows/pan_{0}.assetbundle", viewName); } else { newPath = path; } AssetBundleMgr.Instance.LoadOrDownload(newPath, string.Format("pan_{0}", viewName), (GameObject obj) => { obj = UnityEngine.Object.Instantiate(obj); UIWindowViewBase windowBase = obj.GetComponent <UIWindowViewBase>(); if (windowBase == null) { return; } if (OnShow != null) { windowBase.OnShow = OnShow; } m_DicWindow[viewName] = windowBase; windowBase.ViewName = viewName; Transform transParent = null; switch (windowBase.containerType) { case WindowUIContainerType.Center: transParent = UISceneCtrl.Instance.CurrentUIScene.Container_Center; break; } obj.transform.parent = transParent; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; obj.gameObject.SetActive(false); //层级管理 LayerUIMgr.Instance.SetLayer(obj); StartShowWindow(windowBase, true); if (onComplete != null) { onComplete(obj); } //if (OnCreate != null) //{ // OnCreate(obj); //} }); } else { if (onComplete != null) { GameObject obj = m_DicWindow[viewName].gameObject; //层级管理 LayerUIMgr.Instance.SetLayer(obj); onComplete(obj); } } }
/// <summary> /// 打开窗口 /// </summary> /// <param name="type">窗口类型</param> /// <returns></returns> public GameObject OpenWindow(UIViewType type) { GameObject go = null; //如果窗口不存在 if (!dicWindow.ContainsKey(type) || dicWindow[type] == null) { //UI窗口注意命名格式 必须是pan+UIWindowType枚举类型 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.UIWindow, string.Format("pan{0}", type), true); if (go == null) { return(null); } UIWindowViewBase window = go.GetComponent <UIWindowViewBase>(); if (window == null) { return(null); } if (!dicWindow.ContainsKey(type)) { dicWindow.Add(type, window); } else { dicWindow[type] = window; } window.ViewType = type; Transform parent = null; switch (window.ContainerType) { case UIWinndowContainerType.Center: parent = UISceneCtrl.Instance.CurrentUIScene.ContainerCenter; break; case UIWinndowContainerType.BL: parent = UISceneCtrl.Instance.CurrentUIScene.ContainerCenter; break; case UIWinndowContainerType.BR: parent = UISceneCtrl.Instance.CurrentUIScene.ContainerCenter; break; case UIWinndowContainerType.TL: parent = UISceneCtrl.Instance.CurrentUIScene.ContainerCenter; break; case UIWinndowContainerType.TR: parent = UISceneCtrl.Instance.CurrentUIScene.ContainerCenter; break; } go.transform.SetParent(parent); go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; go.GetComponent <RectTransform>().sizeDelta = Vector2.zero; go.SetActive(false); ShowWindowAni(window, true); } else { go = dicWindow[type].gameObject; } //设置UI层级管理 LayerMgr.Instance.SetUILayerDepth(go); return(go); }
/// <summary> /// 销毁窗口 /// </summary> /// <param name="obj"></param> private void DestroyWindow(UIWindowViewBase windowBase) { m_DicWindow.Remove(windowBase.ViewName); UnityEngine.Object.Destroy(windowBase.gameObject); }
/// <summary> /// 销毁窗口 /// </summary> private void DestoryWindow(UIWindowViewBase window) { dicWindow.Remove(window.ViewType); GameObject.Destroy(window.gameObject); }