public void Init(WindowID wndId) { bool bContain = LocalDataManager.Instance().m_UIFrame_Dict.ContainsKey(wndId.ToString()); if (!bContain) { ShowFrame(false); Debug.LogWarning(string.Format("该窗口{0}, 还没加入到UIFrame中", wndId.ToString())); return; } dbc.UIFrame frame = LocalDataManager.Instance().m_UIFrame_Dict[wndId.ToString()]; //没有Frame的窗口 if (frame.FrameType == 0) { ShowFrame(false); } //根据窗口类型显示不同的排版显示 //type = 1 顶栏显示 ,其他类型暂时没写 else if (frame.FrameType == 1) { //跟上一次的一样直接显示 if (m_LastFrame != null && m_LastFrame.BarContent.Equals(frame.BarContent)) { ShowFrame(true); } else { ShowFrame(GetFrameItemArray(frame)); } } m_LastFrame = frame; }
protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null) { // 检测控制权限 if (!this.IsWindowInControl(id)) { Debug.Log("UIManager has no control power of " + id.ToString()); return(null); } if (shownWindows.ContainsKey(id)) { return(null); } UIBaseWindow baseWindow = GetGameWindow(id); bool newAdded = false; if (!baseWindow) { newAdded = true; // 窗口不存在从内存进行加载 if (UIResourceDefine.windowPrefabPath.ContainsKey(id)) { string prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[id]; GameObject prefab = Resources.Load <GameObject>(prefabPath); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); NGUITools.SetActive(uiObject, true); baseWindow = uiObject.GetComponent <UIBaseWindow>(); // 需要动态添加对应的控制界面,prefab不用添加脚本 Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform); allWindows[id] = baseWindow; } } } if (baseWindow == null) { Debug.LogError("[window instance is null.]" + id.ToString()); } // 重置界面(第一次添加,强制Reset) if (newAdded || (showData != null && showData.forceResetWindow)) { baseWindow.ResetWindow(); } // 显示界面固定内容 // 导航系统数据更新 RefreshBackSequenceData(baseWindow); // 调整层级depth AdjustBaseWindowDepth(baseWindow); // 添加背景Collider AddColliderBgForWindow(baseWindow); return(baseWindow); }
protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id) { // 检测控制权限 if (!this.IsWindowInControl(id)) { Debug.Log("UIManager has no control power of " + id.ToString()); return(null); } if (ShownWindows.ContainsKey(id)) { return(null); } // 隐藏callWindowId指向窗口 /*if(showData != null) * HideWindow(showData.callWindowId, null);*/ UIBaseWindow baseWindow = GetGameWindow(id); bool newAdded = false; if (!baseWindow) { newAdded = true; // 窗口不存在从内存进行加载 if (AppConst.windowPrefabPath.ContainsKey(id)) { GameObject prefab = ResourcesMgr.Instance.LoadResource <GameObject>(ResourceType.RESOURCE_UI, AppConst.windowPrefabPath[id]); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); Util.SetActive(uiObject, true); baseWindow = uiObject.GetComponent <UIBaseWindow>(); Util.AddChildToTarget(UINormalWindowRoot, baseWindow.transform); AllWindows[id] = baseWindow; } } } if (baseWindow == null) { Debug.LogError("[window instance is null.]" + id.ToString()); return(null); } if (newAdded) { baseWindow.ResetWindow(); } //// 导航系统数据更新 //RefreshBackSequenceData(baseWindow); //// 调整层级depth //AdjustBaseWindowDepth(baseWindow); //// 添加背景Collider //AddColliderBgForWindow(baseWindow); return(baseWindow); }
public override void ShowWindow(WindowID id, ShowWindowData showData) { if (!IsWindowInControl(id)) { Debuger.Log("UIRankManager has no control power of " + id.ToString()); return; } if (dicShownWindows.ContainsKey((int)id)) { return; } if (dicAllWindows.ContainsKey((int)id)) { UIBaseWindow baseWindow = dicAllWindows[(int)id]; if (baseWindow.ID != id) { Debuger.LogError(string.Format("[UIRankManager BaseWindowId :{0} != shownWindowId :{1}]", baseWindow.ID, id)); return; } if (baseWindow.windowData.navigationMode == UIWindowNavigationMode.NormalNavigation) { BackWindowSequenceData backData = new BackWindowSequenceData(); backData.hideTargetWindow = baseWindow; backSequence.Push(backData); } this.RealShowWindow(baseWindow, baseWindow.ID, showData); } }
/// <summary> /// 打开指定窗口,使用指定视图控制器 /// </summary> /// <param name="winId"></param> /// <param name="ctrl"></param> public static void OpenWindow(WindowID winId, IView ctrl = null) { try { if (CtrlManager.mDicOpenCtrls.ContainsKey(winId)) { if (winId == WindowID.TipView) { CtrlManager.OnOpenWindow(new OpenWindowEventArgs(true, winId.ToString(), CtrlManager.mDicOpenCtrls[winId].uiWindow)); } } else { IView view = ctrl; if (view == null) { view = CtrlManager.GetViewInstance(winId); } view.WinId = winId; CtrlManager.mDicWindCtrls[winId] = view; UIManager.Instance.OpenWindow(view.WinId.ToString(), view.WinResCfg); } } catch (Exception e) { ClientLogger.LogException(e); } }
public override void ShowWindow(WindowID id, ShowWindowData showData) { if (!IsWindowInControl(id)) { Debuger.Log("UIRankManager has no control power of " + id.ToString()); return; } if (dicShownWindows.ContainsKey((int)id)) return; if (dicAllWindows.ContainsKey((int)id)) { UIBaseWindow baseWindow = dicAllWindows[(int)id]; if (baseWindow.ID != id) { Debuger.LogError(string.Format("[UIRankManager BaseWindowId :{0} != shownWindowId :{1}]", baseWindow.ID, id)); return; } if (baseWindow.windowData.navigationMode == UIWindowNavigationMode.NormalNavigation) { BackWindowSequenceData backData = new BackWindowSequenceData(); backData.hideTargetWindow = baseWindow; backSequence.Push(backData); } this.RealShowWindow(baseWindow, baseWindow.ID, showData); } }
public void CloseWindow(WindowID wndId) { if (!IsWindowInControl(wndId)) { Debuger.LogError("## Current UI Manager has no control power of " + wndId.ToString()); return; } if (!dicShownWindows.ContainsKey((int)wndId)) { return; } UIBaseWindow window = dicShownWindows[(int)wndId]; if (this.backSequence.Count > 0) { BackWindowSequenceData seqData = this.backSequence.Peek(); if (seqData != null && seqData.hideTargetWindow == window) { PopNavigationWindow(); Debuger.Log("<color=magenta>## close window use PopNavigationWindow() ##</color>"); return; } } HideWindow(wndId); Debuger.Log("<color=magenta>## close window without PopNavigationWindow() ##</color>"); }
public override void ShowWindow(WindowID id, ShowWindowData data) { if (!IsWindowInControl(id)) { Debug.Log("UIRankManager has no control power of " + id.ToString()); return; } if (shownWindows.ContainsKey(id)) { return; } if (allWindows.ContainsKey(id)) { UIBaseWindow baseWindow = allWindows[id]; if (baseWindow.windowData.showMode == UIWindowShowMode.NeedBack) { BackWindowSequenceData backData = new BackWindowSequenceData(); backData.hideTargetWindow = baseWindow; backSequence.Push(backData); } allWindows[id].ShowWindow(); shownWindows[id] = allWindows[id]; this.lastShownNormalWindow = this.curShownNormalWindow; curShownNormalWindow = baseWindow; } }
public override void ShowWindow(WindowID id, ShowWindowData data) { if (!IsWindowInControl(id)) { Debug.Log("UIRankManager has no control power of " + id.ToString()); return; } if (shownWindows.ContainsKey(id)) return; if (allWindows.ContainsKey(id)) { UIBaseWindow baseWindow = allWindows[id]; if (baseWindow.windowData.showMode == UIWindowShowMode.NeedBack) { BackWindowSequenceData backData = new BackWindowSequenceData(); backData.hideTargetWindow = baseWindow; backSequence.Push(backData); } allWindows[id].ShowWindow(); shownWindows[id] = allWindows[id]; this.lastShownNormalWindow = this.curShownNormalWindow; curShownNormalWindow = baseWindow; } }
private void RealShow(WindowID windowId, bool bAppend) { string wndPath = wndResDict [windowId]; GameObject prefab = null; if (GameManager.Instance.ResFrom != ResourceFrom.Bundle) { prefab = ResourceManager.LoadResource("UIPrefab/" + windowId.ToString()) as GameObject; } else { prefab = ResourceManager.GetInstance().LoadAsset(wndPath, windowId.ToString()); } if (prefab != null) { GameObject clone = (GameObject)GameObject.Instantiate(prefab); UnityTools.AddChildToTarget(wndRoot.transform, clone.transform); UIWndBase wnd = clone.GetComponent <UIWndBase> (); wnd.status = WindowStatus.Active; if (curShowWnd != null) { wnd.preWndID = curShowWnd.wndID; } wnd.wndID = windowId; if (bAppend) { if (backStack.Count == 0) { backStack.Push(curShowWnd); } curShowWnd = wnd; backStack.Push(curShowWnd); AdjustAlpha(); } else { curShowWnd = wnd; HideAllCach(); BreakBackStack(); } cacheWndDict.Add(windowId, curShowWnd); curShowWnd.AdjustAlpha(1.0f); CheckCach(); wnd.Refresh(); } }
/// <summary> /// 关闭指定窗口 /// </summary> /// <param name="winId"></param> public static void CloseWindow(WindowID winId) { if (!CtrlManager.mDicOpenCtrls.ContainsKey(winId)) { return; } UIManager.Instance.CloseWindow(winId.ToString()); }
protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null) { // 检测控制权限 if (!this.IsWindowInControl(id)) { Debug.Log("UIManager has no control power of " + id.ToString()); return null; } if (shownWindows.ContainsKey(id)) return null; // 隐藏callWindowId指向窗口 /*if(showData != null) HideWindow(showData.callWindowId, null);*/ UIBaseWindow baseWindow = GetGameWindow(id); bool newAdded = false; if (!baseWindow) { newAdded = true; // 窗口不存在从内存进行加载 if (UIResourceDefine.windowPrefabPath.ContainsKey(id)) { string prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[id]; GameObject prefab = Resources.Load<GameObject>(prefabPath); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); NGUITools.SetActive(uiObject, true); baseWindow = uiObject.GetComponent<UIBaseWindow>(); // 需要动态添加对应的控制界面,prefab不用添加脚本 Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform); allWindows[id] = baseWindow; } } } if (baseWindow == null) Debug.LogError("[window instance is null.]" + id.ToString()); // 重置界面(第一次添加,强制Reset) if (newAdded || (showData != null && showData.forceResetWindow)) baseWindow.ResetWindow(); // 显示界面固定内容 // 导航系统数据更新 RefreshBackSequenceData(baseWindow); // 调整层级depth AdjustBaseWindowDepth(baseWindow); // 添加背景Collider AddColliderBgForWindow(baseWindow); return baseWindow; }
/// <summary> /// 窗口显示,队列型加载 /// </summary> public void ShowWindow(WindowID windowId, bool bAppend = false) { if (wndResDict.ContainsKey(windowId)) { if (cacheWndDict.ContainsKey(windowId)) { UIWndBase wnd = cacheWndDict [windowId]; if (wnd.status == WindowStatus.Inactive) { if (bAppend) { if (backStack.Count == 0) { backStack.Push(curShowWnd); } backStack.Push(wnd); AdjustAlpha(); } else { HideAllCach(); BreakBackStack(); curShowWnd.Close(); } wnd.Show(); curShowWnd = wnd; } else if (wnd.status == WindowStatus.Gray) { curShowWnd.Close(); curShowWnd = wnd; backStack.Pop(); AdjustAlpha(); } else if (wnd.status == WindowStatus.Active) { Debug.Log("当前窗口已经是显示窗口"); } wnd.Refresh(); } else { RealShow(windowId, bAppend); } } else { Debug.Log(windowId.ToString() + " 不存在资源"); } }
/// <summary> /// Navigation reShow target windows /// </summary> protected void ShowWindowForNavigation(WindowID id) { if (!this.IsWindowInControl(id)) { Debuger.Log("## Current UI Manager has no control power of " + id.ToString()); return; } if (dicShownWindows.ContainsKey((int)id)) { return; } UIBaseWindow baseWindow = GetGameWindow(id); baseWindow.ShowWindow(); dicShownWindows[(int)baseWindow.ID] = baseWindow; }
/// <summary> /// Navigation reShow target windows /// </summary> private void ShowWindowForNavigation(WindowID id) { if (!this.IsWindowInControl(id)) { Debug.Log("## Current UI Manager has no control power of " + id.ToString()); return; } if (dicShownWindows.ContainsKey(id)) { return; } UIWindowBase baseWindow = GetGameWindow(id); baseWindow.ReadyToShowWindow(); dicShownWindows[baseWindow.ID] = baseWindow; }
// 直接打开窗口 protected void ShowWindowForBack(WindowID id) { // 检测控制权限 if (!this.IsWindowInControl(id)) { Debug.Log("UIManager has no control power of " + id.ToString()); return; } if (shownWindows.ContainsKey(id)) { return; } UIBaseWindow baseWindow = GetGameWindow(id); baseWindow.ShowWindow(); shownWindows[baseWindow.GetID] = baseWindow; }
//version79.3 private static UIViewBase PreparePrefab(WindowID id, object asset) { //加载成功 GameObject prefab = asset as GameObject; if (prefab != null) { GameObject uiObject = GameObject.Instantiate(prefab); uiObject.SetActive(true); //获取UIViewBase脚本或者添加 UIViewBase uiView = uiObject.GetComponent <UIViewBase>(); if (uiView == null) { WindowID UIID = (WindowID)Enum.Parse(typeof(WindowID), id.ToString()); string UIViewScriptName = UIID.ToString() + UIGlobalDefine.ViewScriptSuffix; Debug.LogWarning("Prefab没有添加脚本!!!!" + UIViewScriptName); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { Type t = assembly.GetType(string.Format("{0}.{1}", UIGlobalDefine.UINameSPace, UIViewScriptName)); //version44.2 if (t != null) { uiView = uiObject.AddComponent(t) as UIViewBase; break; } } } if (uiView.ID != id) { Debug.LogError(string.Format("<color=cyan>[UIViewBase.ID :{0} != shownWindowId :{1}]</color>", uiView.ID, id)); return(null); } uiView.Controller.Asset = prefab;//version79.4 return(uiView); } return(null); }
/// <summary> /// Check condition to hide the target window /// </summary> protected void CheckDirectlyHide(WindowID id, Action onComplete) { if (!IsWindowInControl(id)) { Debug.Log("## Current UI Manager has no control power of " + id.ToString()); return; } if (!dicShownWindows.ContainsKey(id)) { return; } if (!isNeedWaitHideOver) { dicShownWindows[id].ReadyToCloseWindow(() => { dicShownWindows.Remove(id); }); if (onComplete != null)//不放在回调里面的原因是。上一个窗口的退出和后面一个窗口的进入会产生交错感 { onComplete(); } return; } if (dicShownWindows.ContainsKey(id)) { if (onComplete != null) { onComplete += delegate { dicShownWindows.Remove(id); }; dicShownWindows[id].ReadyToCloseWindow(onComplete); } else { dicShownWindows[id].ReadyToCloseWindow(onComplete); dicShownWindows.Remove(id); } } }
/// <summary> /// 关闭窗口。如果有导航就返回上一个界面 /// 如果没有就直接根据窗口的设定关闭或者隐藏窗口 /// </summary> /// <param name="wndId"></param> public void CloseWindow(WindowID wndId) { if (!IsWindowInControl(wndId)) { Debug.LogError("## Current UI Manager has no control power of " + wndId.ToString()); return; } if (!dicShownWindows.ContainsKey(wndId)) { return; } UIWindowBase window = dicShownWindows[wndId]; if (this.backSequence.Count > 0) { NavigationData seqData = this.backSequence.Peek(); if (seqData != null && seqData.CloseTargetWindow == window) { PopNavigationWindow(); Debug.Log("<color=magenta>## close window use PopNavigationWindow() ##</color>"); return; } } switch (dicShownWindows[wndId].windowData.closeModel) { case UIWindowCloseModel.Destory: DestroyWindow(wndId, null); break; case UIWindowCloseModel.Hide: HideWindow(wndId); break; } // HideWindow(wndId); Debug.Log("<color=magenta>## close window without PopNavigationWindow() ##</color>"); }
/// <summary> /// Check condition to hide the target window /// </summary> protected void CheckDirectlyHide(WindowID id, Action onComplete) { if (!IsWindowInControl(id)) { Debuger.Log("## Current UI Manager has no control power of " + id.ToString()); return; } if (!dicShownWindows.ContainsKey((int)id)) { return; } if (!isNeedWaitHideOver) { if (onComplete != null) { onComplete(); } dicShownWindows[(int)id].HideWindow(null); dicShownWindows.Remove((int)id); return; } if (dicShownWindows.ContainsKey((int)id)) { if (onComplete != null) { onComplete += delegate { dicShownWindows.Remove((int)id); }; dicShownWindows[(int)id].HideWindow(onComplete); } else { dicShownWindows[(int)id].HideWindow(onComplete); dicShownWindows.Remove((int)id); } } }
protected virtual void CheckDirectlyHide(WindowID id, Action onComplete) { if (!IsWindowInControl(id)) { Debug.Log("UIRankManager has no control power of " + id.ToString()); return; } if (!shownWindows.ContainsKey(id)) { return; } if (!isNeedWaitHideOver) { if (onComplete != null) { onComplete(); } shownWindows[id].HideWindow(null); shownWindows.Remove(id); return; } if (shownWindows.ContainsKey(id)) { if (onComplete != null) { onComplete += delegate { shownWindows.Remove(id); }; shownWindows[id].HideWindow(onComplete); } else { shownWindows[id].HideWindow(onComplete); shownWindows.Remove(id); } } }
protected virtual void WindowDirectlyHide(WindowID id, Action onComplete) { if (!IsWindowInControl(id)) { Debug.Log("UIRankManager has no control power of " + id.ToString()); return; } if (!shownWindows.ContainsKey(id)) { return; } if (onComplete != null) { onComplete(); } shownWindows[id].HideWindow(null); shownWindows.Remove(id); }
protected void ShowWindowForOtherWindowManager(WindowID id, ShowWindowData showData) { if (!IsWindowInControl(id)) { Debug.Log("UIRankManager has no control power of " + id.ToString()); return; } if (dicShownWindows.ContainsKey(id)) { return; } if (dicAllWindows.ContainsKey(id)) { UIWindowBase baseWindow = dicAllWindows[id]; if (baseWindow.ID != id) { Debug.LogError(string.Format("[UIRankManager BaseWindowId :{0} != shownWindowId :{1}]", baseWindow.ID, id)); return; } this.RealShowWindow(baseWindow, baseWindow.ID, showData); } }
private UIBase getWindow(WindowID id) { if (id == WindowID.Max) { return(null); } UIBase ui = uiWindows[(int)id]; if (!ui) { string path = string.Format("Prefabs/UI/{0}", id.ToString()); UnityEngine.Object prefab = Resources.Load(path); if (prefab == null) { return(null); } else { GameObject go = Instantiate(prefab) as GameObject; go.name = prefab.name; ui = go.GetComponent <UIBase>(); if (!ui) { return(null); } go.transform.SetParent(transform, false); uiWindows[(int)id] = ui; ui.ID = id; go.SetActive(false); } } return(ui); }
protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null) { // Check the window control state if (!this.IsWindowInControl(id)) { Debuger.Log("## UIManager has no control power of " + id.ToString()); return null; } // If the window in shown list just return if (dicShownWindows.ContainsKey((int)id)) return null; UIBaseWindow baseWindow = GetGameWindow(id); // If window not in scene start Instantiate new window to scene bool newAdded = false; if (!baseWindow) { newAdded = true; if (UIResourceDefine.windowPrefabPath.ContainsKey((int)id)) { string prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[(int)id]; GameObject prefab = Resources.Load<GameObject>(prefabPath); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); NGUITools.SetActive(uiObject, true); // NOTE: You can add component to the window in the inspector // Or just AddComponent<UIxxxxWindow>() to the target baseWindow = uiObject.GetComponent<UIBaseWindow>(); if (baseWindow.ID != id) { Debuger.LogError(string.Format("<color=cyan>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id)); return null; } // Get the window target root parent Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform); dicAllWindows[(int)id] = baseWindow; } } } if (baseWindow == null) Debuger.LogError("[window instance is null.]" + id.ToString()); // Call reset window when first load new window // Or get forceResetWindow param if (newAdded || (showData != null && showData.forceResetWindow)) baseWindow.ResetWindow(); if (showData == null || (showData != null && showData.executeNavLogic)) { // refresh the navigation data ExecuteNavigationLogic(baseWindow, showData); } // Adjust the window depth AdjustBaseWindowDepth(baseWindow); // Add common background collider to window AddColliderBgForWindow(baseWindow); return baseWindow; }
protected bool PopNavigationWindow() { #region 导航信息为空 if (backSequence.Count == 0) { if (curNavigationWindow == null) { return(false); } //如果当前navigation的栈是空, 就检查当前UI的配置PrewindowID, 打开 WindowID preWindowId = curNavigationWindow.UIConfigData.PreWindowId; if (preWindowId != WindowID.WindowID_Invaild) { Debug.LogWarning(string.Format(string.Format("## Current nav window {0} need show pre window {1}.", curNavigationWindow.ID.ToString(), preWindowId.ToString()))); HideWindow(curNavigationWindow.ID, delegate { //不执行导航 WindowContextDataBase showData = new WindowContextDataBase(); showData.executeNavLogic = false; ShowWindow(preWindowId, showData); }); } else { Debug.LogWarning("## CurrentShownWindow " + curNavigationWindow.ID + " preWindowId is " + WindowID.WindowID_Invaild); } return(false); } #endregion NavigationData backData = backSequence.Peek(); if (backData != null) { // check the current navigation data int curId = this.GetCurrentShownWindow(); if (curId != (int)backData.showingUI.ID) { Debug.Log("<color=red>当前导航Stack里面信息不对 [backData.showingUI.ID != this.curShownWindowId]</color>"); return(false); } //关闭当前的UI, 恢复显示stack里面保存的UI WindowID showingId = backData.showingUI.ID; if (!dicShownWindows.ContainsKey((int)showingId)) { PopNavigationUI(backData); } else { HideWindow(showingId, delegate { PopNavigationUI(backData); }); } } return(true); }
private void Button_Click(object sender, RoutedEventArgs e) { _proxy.NotifyOthers(WindowID.ToString()); }
protected override UIWindowBase ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null) { // Check the window control state if (!this.IsWindowInControl(id)) { Debug.Log("## UIManager has no control power of " + id.ToString()); return(null); } // If the window in shown list just return if (dicShownWindows.ContainsKey(id)) { return(null); } UIWindowBase baseWindow = GetGameWindow(id); // If window not in scene start Instantiate new window to scene bool newAdded = false; if (!baseWindow) { newAdded = true; if (UIResourceDefine.windowPrefabPath.ContainsKey(id)) { GameObject prefab = Resources.Load <GameObject>(UIResourceDefine.windowPrefabPath[id]); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); //// NGUITools.SetActive(uiObject, true); //// NOTE: You can add component to the window in the inspector //// Or just AddComponent<UIxxxxWindow>() to the target baseWindow = uiObject.GetComponent <UIWindowBase>(); if (baseWindow.ID != id) { Debug.LogError(string.Format("<color=#2a5caa>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id)); return(null); } // Get the window target root parent Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); Transform t = uiObject.transform; t.SetParent(targetRoot.transform); t.localPosition = Vector3.zero; t.localRotation = Quaternion.identity; t.localScale = Vector3.one; uiObject.layer = targetRoot.gameObject.layer; RectTransform _targetRectTransform = uiObject.GetComponent <RectTransform>(); if (_targetRectTransform.anchorMax == Vector2.one && _targetRectTransform.anchorMin == Vector2.zero) { //如果是拉伸就吧边角设置成0 UGUITools.SetRectTransformOffset(uiObject, Vector2.zero, Vector2.zero); } UGUITools.SetRectTransformAnchoredPosition(uiObject, Vector2.zero); // baseWindow = UGUITools.AddChild(targetRoot.gameObject, prefab).GetComponent<UIWindowBase>(); if (baseWindow.ID != id) { Debug.LogError(string.Format("<color=#2a5caa>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id)); return(null); } dicAllWindows[id] = baseWindow; prefab = null; } } } if (baseWindow == null) { Debug.LogError("[window instance is null.]" + id.ToString()); } // Call reset window when first load new window // Or get forceResetWindow param if (newAdded || (showData != null && showData.forceResetWindow)) { baseWindow.ResetWindow(); } if (showData == null || (showData != null && showData.executeNavLogic)) { // refresh the navigation data ExecuteNavigationLogic(baseWindow, showData); } // Adjust the window depth AdjustBaseWindowDepth(baseWindow); // Add common background collider to window AddColliderBgForWindow(baseWindow); return(baseWindow); }
private UIControllerBase PrepareUI(WindowID id, WindowContextDataBase showContextData = null) { if (!this.IsWindowRegistered(id)) { return(null); } if (dicShownWindows.ContainsKey((int)id)) { return(null); } UIControllerBase baseController = GetGameWindowFromCache(id); //UI没有在场景里打开过, Instantiate New One bool newAdded = false; if (baseController == null) { newAdded = true; if (UIResourceDefine.windowPrefabPath.ContainsKey((int)id)) { //实例化UI UIViewBase uiView = GameUIUtility.InstantiateUI(id); //保存Controller baseController = uiView.Controller; dicWindowsCache[(int)id] = baseController; //初始化 baseController.OnInit(); //设置UI根 Transform targetRoot = GameUIUtility.GetUIRoot();//UINormalWindowRoot; GameUIUtility.AddChildToTarget(targetRoot, uiView.gameObject.transform); //设置UI Camera Canvas uiCanvas = uiView.gameObject.GetComponent <Canvas>(); uiCanvas.renderMode = RenderMode.ScreenSpaceCamera; { GameObject uiCamera = GameObject.Find("UICamera"); if (uiCamera != null) { uiCanvas.worldCamera = uiCamera.GetComponent <Camera>(); } } //添加通用背景 AddColliderBgForWindow(uiView); } else { Debug.LogError("UI ID对应的Prefab位置在找不到, 使用工具重新生成 " + id); return(null); } } if (baseController == null) { Debug.LogError("[UI instance is null.]" + id.ToString()); } //设置导航信息, 如果是导航类型的UI会把当前显示的UI关闭并且保存到BackSequenceStack里面 //下次返回的时候, 从Stack里面回复. if (showContextData == null || (showContextData != null && showContextData.executeNavLogic)) { ExecuteNavigationLogic(baseController); } //层级管理 //AdjustBaseWindowDepth(baseController); return(baseController); }
protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null) { // Check the window control state if (!this.IsWindowInControl(id)) { Debuger.Log("## UIManager has no control power of " + id.ToString()); return(null); } // If the window in shown list just return if (dicShownWindows.ContainsKey((int)id)) { return(null); } UIBaseWindow baseWindow = GetGameWindow(id); // If window not in scene start Instantiate new window to scene bool newAdded = false; if (!baseWindow) { newAdded = true; if (UIResourceDefine.windowPrefabPath.ContainsKey((int)id)) { string prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[(int)id]; GameObject prefab = Resources.Load <GameObject>(prefabPath); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); NGUITools.SetActive(uiObject, true); // NOTE: You can add component to the window in the inspector // Or just AddComponent<UIxxxxWindow>() to the target baseWindow = uiObject.GetComponent <UIBaseWindow>(); if (baseWindow.ID != id) { Debuger.LogError(string.Format("<color=cyan>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id)); return(null); } // Get the window target root parent Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform); dicAllWindows[(int)id] = baseWindow; } } } if (baseWindow == null) { Debuger.LogError("[window instance is null.]" + id.ToString()); } // Call reset window when first load new window // Or get forceResetWindow param if (newAdded || (showData != null && showData.forceResetWindow)) { baseWindow.ResetWindow(); } if (showData == null || (showData != null && showData.executeNavLogic)) { // refresh the navigation data ExecuteNavigationLogic(baseWindow, showData); } // Adjust the window depth AdjustBaseWindowDepth(baseWindow); // Add common background collider to window AddColliderBgForWindow(baseWindow); return(baseWindow); }
protected bool RealPopNavigationWindow() { if (backSequence.Count == 0) { if (curNavigationWindow == null) { return(false); } if (PopUpWindowManager(curNavigationWindow)) { return(true); } // if curNavigationWindow BackSequenceData is null // Check window's preWindowId // if preWindowId defined just move to target Window(preWindowId) WindowID preWindowId = curNavigationWindow.PreWindowID; if (preWindowId != WindowID.Invaild) { Debug.LogWarning(string.Format(string.Format("## Current nav window {0} need show pre window {1}.", curNavigationWindow.ID.ToString(), preWindowId.ToString()))); switch (curNavigationWindow.windowData.closeModel) { case UIWindowCloseModel.Hide: { HideWindow(curNavigationWindow.ID, delegate { ShowWindowData showData = new ShowWindowData(); showData.executeNavLogic = false; ShowWindow(preWindowId, showData); }); } break; case UIWindowCloseModel.Destory: { DestroyWindow(curNavigationWindow.ID, delegate { ShowWindowData showData = new ShowWindowData(); showData.executeNavLogic = false; ShowWindow(preWindowId, showData); }); } break; } } else { Debug.LogWarning("## CurrentShownWindow " + curNavigationWindow.ID + " preWindowId is " + WindowID.Invaild); } return(false); } NavigationData backData = backSequence.Peek(); if (backData != null) { // check the current navigation data WindowID curId = this.GetCurrentShownWindow(); if (curId != backData.CloseTargetWindow.ID) { Debug.Log("<color=red>Can't PopUp seq data [backData.hideTargetWindow.ID != this.curShownWindowId]</color>"); return(false); } if (PopUpWindowManager(backData.CloseTargetWindow)) { return(true); } WindowID closeId = backData.CloseTargetWindow.ID; if (!dicShownWindows.ContainsKey(closeId)) { ExectuteBackSeqData(backData); } else { switch (backData.CloseTargetWindow.windowData.closeModel) { case UIWindowCloseModel.Hide: { HideWindow(closeId, delegate { ExectuteBackSeqData(backData); }); } break; case UIWindowCloseModel.Destory: { CheckDirectlyDestroyWIndow(closeId, delegate { ExectuteBackSeqData(backData); }); } break; } } } return(true); }
/// <summary> /// 窗口显示,队列型加载 /// </summary> public void ShowWindow(WindowID windowId, bool bAppend = false) { if (instance == null) { Init(); } if (FrameRoot == null) { GameObject prefab = ResourcesManager.Load <GameObject>("BuildIn/Frame/UIFrame"); FrameRoot = Util.NewGameObject(prefab, wndRoot).GetComponent <UIFrame>(); } FrameRoot.Init(windowId); if (wndResDict.ContainsKey(windowId)) { if (cacheWndDict.ContainsKey(windowId)) { UIWndBase wnd = cacheWndDict [windowId]; Log("缓存中, 状态是:" + wnd.status.ToString()); if (wnd.status == WindowStatus.Inactive) { if (bAppend) { if (backStack.Count == 0) { backStack.Push(curShowWnd); } backStack.Push(wnd); AdjustAlpha(); } else { HideAllCach(); BreakBackStack(); curShowWnd.Close(); } wnd.Show(); curShowWnd = wnd; } else if (wnd.status == WindowStatus.Gray) { curShowWnd.Close(); curShowWnd = wnd; backStack.Pop(); AdjustAlpha(); } else if (wnd.status == WindowStatus.Active) { Log("当前窗口已经是显示窗口"); } wnd.Refresh(); } else { Log("新加入窗口:" + windowId.ToString()); RealShow(windowId, bAppend); } } else { Log(windowId.ToString() + " 不存在资源"); } }
private void RealShow(WindowID windowId, bool bAppend) { string wndPath = wndResDict [windowId]; string panelPath = string.Format("{0}Panel/{1}", AssetDefine.ResRoot, windowId.ToString()); GameObject prefab = ResourcesManager.Load <GameObject>(panelPath); if (prefab != null) { GameObject clone = (GameObject)GameObject.Instantiate(prefab); XFramework.Utility.Util.AddChildToTarget(wndRoot.transform, clone.transform); UIWndBase wnd = clone.GetComponent <UIWndBase> (); wnd.status = WindowStatus.Active; if (curShowWnd != null) { wnd.preWndID = curShowWnd.wndID; } wnd.wndID = windowId; if (bAppend) { Log("push into stack " + curShowWnd.wndID.ToString()); if (backStack.Count == 0) { backStack.Push(curShowWnd); } curShowWnd = wnd; backStack.Push(curShowWnd); AdjustAlpha(); } else { curShowWnd = wnd; HideAllCach(); BreakBackStack(); } cacheWndDict.Add(windowId, curShowWnd); curShowWnd.AdjustAlpha(1.0f); CheckCach(); wnd.Refresh(); } }
protected bool RealPopNavigationWindow() { if (backSequence.Count == 0) { if (curNavigationWindow == null) { return(false); } if (PopUpWindowManager(curNavigationWindow)) { return(true); } // if curNavigationWindow BackSequenceData is null // Check window's preWindowId // if preWindowId defined just move to target Window(preWindowId) WindowID preWindowId = curNavigationWindow.PreWindowID; if (preWindowId != WindowID.WindowID_Invaild) { Debuger.LogWarning(string.Format(string.Format("## Current nav window {0} need show pre window {1}.", curNavigationWindow.ID.ToString(), preWindowId.ToString()))); HideWindow(curNavigationWindow.ID, delegate { ShowWindowData showData = new ShowWindowData(); showData.executeNavLogic = false; ShowWindow(preWindowId, showData); }); } else { Debuger.LogWarning("## CurrentShownWindow " + curNavigationWindow.ID + " preWindowId is " + WindowID.WindowID_Invaild); } return(false); } BackWindowSequenceData backData = backSequence.Peek(); if (backData != null) { // check the current back data int curId = this.GetCurrenShownWindow(); if (curId != (int)backData.hideTargetWindow.ID) { Debuger.Log("<color=red>Can't PopUp seq data [backData.hideTargetWindow.ID != this.curShownWindowId]</color>"); return(false); } if (PopUpWindowManager(backData.hideTargetWindow)) { return(true); } WindowID hideId = backData.hideTargetWindow.ID; if (!dicShownWindows.ContainsKey((int)hideId)) { ExectuteBackSeqData(backData); } else { HideWindow(hideId, delegate { ExectuteBackSeqData(backData); }); } } return(true); }