private void doClose(UIWin win, object message = null) { if (win) { openWins.Remove(win); win.gameObject.SetActive(false); win.Close(message); if (winAction != null) { if (openWins.Last != null) { UIWin lastWin = openWins.Last.Value; if (lastWin.backdrop) { winAction(lastWin.transform); } else { winAction(null); } } else { winAction(null); } } } }
/// <summary> /// close the win. /// </summary> /// <param name="win"></param> /// <param name="message">the param pass back in OnClose</param> /// <param name="doRefresh">if need refresh the other normal win. only used for normal window</param> /// <returns></returns> public void CloseWindow(UIWin win, object message = null, bool doRefresh = true) { try { if (win && IsOpen(win.ID)) { //这里需要先关闭窗口(CloseNormalWin),因为在win Close里面很可能调用CLOSEALL, CLOSEALL又会调用到该win的CloseWindow,造成死循环 if (win.closeAnim) { win.PlayCloseAnim(() => { doClose(win, message); if (win.eLayer == EUILayer.Normal) { CloseNormalWin(win, doRefresh); } CheckBack(); }); } else { doClose(win, message); if (win.eLayer == EUILayer.Normal) { CloseNormalWin(win, doRefresh); } CheckBack(); } } } catch (System.Exception ex) { Debug.LogException(ex); } }
private void InitItem() { //hide all of the ui at first. we will show them by special state for (int i = 0; i < transform.childCount; ++i) { Transform child = transform.GetChild(i); //add exist UIs under to the UIManager UIWin ui = child.GetComponent <UIWin>(); if (ui != null) { try { //Main.Log("add ui:==+++++=" + ui.GetType()); WinID ID = (WinID)Enum.Parse(typeof(WinID), ui.GetType().ToString()); //Main.Log("add ui:====" + uiType); UIInstances[(int)ID] = ui; ui.ID = ID; child.gameObject.SetActive(false); } catch (System.Exception ex) { // Main.LogWarning("Unsupport UI" + child.name); } } } }
public bool OpenWindow(UIWinID winID) { if (winID >= UIWinID.UI_None) { return(false); } UIWin win = null; m_cacheUIs.TryGetValue(winID, out win); if (win == null) { UnityEngine.GameObject ui = _LoadUIPrefab(winID); if (ui != null) { win = ui.GetComponent <UIWin>(); m_cacheUIs.Add(winID, win); Log.Info("cache ui:{0}", winID); } } else { win.gameObject.SetActive(true); } win.OnOpen(); return(true); }
private void DestroyUINode(WinID ID) { UIWin win = UIInstances[(int)ID]; if (win) { if (openWins.Contains(win)) { openWins.Remove(win); win.Close(null); if (winAction != null) { if (openWins.Last != null) { UIWin lastWin = openWins.Last.Value; if (lastWin.backdrop) { winAction(lastWin.transform); } else { winAction(null); } } else { winAction(null); } } } NGUITools.Destroy(win.gameObject); UIInstances[(int)ID] = null; } }
private void closeWin(UIWin win, object message, bool doRefresh) { doClose(win, message); if (win.type == UIType.Update) { if (doRefresh && !refreshing) { refreshing = true; if (openWins.Count > 0) { UIWin lastWin = openWins.Last.Value; if (lastWin && lastWin.type != UIType.Main) { lastWin.Refresh(); lastWin.gameObject.SetActive(true); } } refreshing = false; } else { if (openWins.Count > 0) { UIWin lastWin = openWins.Last.Value; if (lastWin && lastWin.type != UIType.Main) { lastWin.gameObject.SetActive(true); } } } } }
public bool PlayOpenAnim(float parentDelay = 0) { if (openAnim && AnimDelay >= 0) { transform.localScale = Vector3.zero; Animation anim = UIWin.SafeGetComponent <Animation>(gameObject); anim.enabled = true; anim.playAutomatically = false; if (anim[openAnim.name] == null) { anim.AddClip(openAnim, openAnim.name); } Invoke("DoPlayAnim", AnimDelay + parentDelay); return(true); } else { CancelInvoke("DoPlayAnim"); if (GetComponent <Animation>()) { GetComponent <Animation>().enabled = false; } return(false); } }
//public Action<UIWin> OnOpenWin; public UIWin OpenWindow(WinID winID, Action <object> onClose = null, params object[] args) { try { if (winID > WinID.UIUnSupport) { // UITipManager.Instance().ShowTip(11102); return(null); } UIWin win = getUI(winID); if (win) { if (win.ReOpenable || !IsOpen(winID)) { openWindow(win, onClose, args); } } return(win); } catch (System.Exception ex) { Debug.LogException(ex); return(null); } }
private void doClose(UIWin win, object message = null) { if (win) { win.gameObject.SetActive(false); win.Close(message); } }
private UIWin getUI(WinID ID) { UIWin UI = null; try { if (ID == WinID.Max) { return(null); } UI = UIInstances[(int)ID]; if (UI == null) { //there is none can use, then add a new one string path = string.Format("UI/{0}", ID); UnityEngine.Object prefab = Resources.Load(path); if (prefab == null) { Logger.LogWarning(string.Format("UI/{0} is not exist!", ID)); return(null); } else { GameObject go = (GameObject)Instantiate(prefab); go.name = prefab.name; UI = go.GetComponent <UIWin>(); if (!UI) { Logger.LogError(string.Format("UI:{0} has not UIWin component!", ID)); return(null); } Transform trans = go.transform; trans.parent = transform; //统一缩放面板 change by zhuliang trans.localScale = Vector3.one;//new Vector3(1.5f,1.5f,1f);// //UpdateLocalScaleByFather(trans,trans); trans.localPosition = new Vector3(0, 0, (float)UI.type); UIInstances[(int)ID] = UI; UI.ID = ID; //init anchor //UIAnchor[] anchors = UI.GetComponentsInChildren<UIAnchor>(); //foreach (var anchor in anchors) //{ // anchor.runOnlyOnce = false; // anchor.uiCamera = UICamera.currentCamera; //} go.SetActive(false); } } return(UI); } catch (System.Exception ex) { Debug.LogException(ex); return(null); } }
private UIWin getUI(WinID ID) { UIWin UI = null; try { if (ID == WinID.Max) { return(null); } UI = UIInstances[(int)ID]; if (UI == null) { //there is none can use, then add a new one UnityEngine.Object prefab = Resources.Load(string.Format("UI/{0}", ID)); if (prefab == null) { Debug.LogWarning(string.Format("UI/{0} is not exist!", ID)); return(null); } else { GameObject go = (GameObject)Instantiate(prefab); go.name = prefab.name; UI = go.GetComponent <UIWin>(); if (!UI) { Debug.LogError(string.Format("UI:{0} has not UIWin component!", ID)); return(null); } Transform trans = go.transform; trans.parent = transform; trans.localScale = Vector3.one; trans.localPosition = new Vector3(0, 0, (float)UI.eLayer); UIInstances[(int)ID] = UI; UI.ID = ID; //init anchor UIAnchor anchor = UI.GetComponent <UIAnchor>(); if (anchor) { anchor.runOnlyOnce = true; anchor.uiCamera = UICamera.currentCamera; } go.SetActive(false); } } return(UI); } catch (System.Exception ex) { Debug.LogException(ex); return(null); } }
private void openWindow(UIWin win, Action <object> onClose, params object[] args) { if (win.eLayer == EUILayer.Normal) { OpenNormalWin(win, onClose, args); } //play animation win.gameObject.SetActive(true); win.Open(onClose, args); CheckBack(); }
public void CloseWindow(WinID winID, object message = null) { try { if (!UIInstances[(int)winID]) { return; } UIWin ui = getUI(winID); DoCloseWindow(ui, message); } catch (System.Exception ex) { Debug.LogException(ex); } }
public bool IsOpen(WinID id) { UIWin win = UIInstances[(int)id]; if (win == null) { return(false); } else { return(openWins.Contains(win)); } }
private bool OnBack() { if (openWins.Last == null) { return(false); } UIWin curWin = openWins.Last.Value; if (!curWin.backdrop) { return(false); } DoCloseWindow(curWin); return(true); }
public void CloseWin(string winName, bool destroy = true) { if (winDic.ContainsKey(winName)) { UIWin win = winDic [winName]; winDic.Remove(winName); win.Close(destroy); } else { Log.e("UIManager", "CloseWin", "尝试关闭不存在的win name:" + winName, BeShowLog); } }
public void Open(UIWin parent, params object[] args) { Parent = parent; if (!inited) { Init(); } try { OnOpen(args); } catch (System.Exception ex) { Debug.LogException(ex); } }
Transform GetParent(UIWin win) { if (win == null) { return(null); } switch (win.winType) { case winType.FullScreen: return(fullScreenLayer); case winType.Popup: return(fullScreenLayer); case winType.Tip: return(fullScreenLayer); } return(null); }
/// <summary> /// 关闭window /// </summary> /// <param name="winName"></param> /// <param name="cb"></param> public void CloseWindow(string winName) { if (string.IsNullOrEmpty(winName)) { Debug.Log("window name is null"); return; } GameObject go = FindWindow(winName); if (go != null) { UIWin win = go.GetComponent <UIWin>(); if (win != null) { win.Close(); } } }
//销毁UI public void Destroy(WinID ID) { UIWin win = UIInstances[(int)ID]; if (!win) { return; } if (IsOpen(ID)) { win.closeAnim = null; //needn't play animation. destory it now! CloseWindow(win); } NGUITools.Destroy(win.gameObject); UIInstances[(int)ID] = null; Resources.UnloadUnusedAssets(); GC.Collect(); }
private void InitItem() { for (int i = 0; i < transform.childCount; ++i) { Transform child = transform.GetChild(i); UIWin ui = child.GetComponent <UIWin>(); if (ui != null) { try { WinID ID = (WinID)Enum.Parse(typeof(WinID), ui.GetType().ToString()); UIInstances[(int)ID] = ui; ui.ID = ID; child.gameObject.SetActive(false); } catch (System.Exception ex) { Logger.LogWarning("Unsupport UI" + child.name); } } } }
public void CloseWindow(UIWinID winID, bool destory = false) { UIWin win = null; m_cacheUIs.TryGetValue(winID, out win); if (win == null) { return; } win.gameObject.SetActive(false); win.OnClose(); if (destory == true) { m_cacheUIs.Remove(winID); GameObject.Destroy(win.gameObject); } }
public bool IsOpen(WinID id) { UIWin win = UIInstances[(int)id]; if (win == null) { return(false); } else { if (win.eLayer == EUILayer.Normal) { return(openedNormalWins.Contains(win)); } else { return(win.gameObject.activeSelf); } } }
//关闭除Main层之外的界面 public void CloseAll() { try { for (int i = openWins.Count - 1; i >= 0; i--) { LinkedListNode <UIWin> last = openWins.Last; if (last == null) { continue; } UIWin ui = last.Value; if (ui.type != UIType.Main) { doClose(ui); } } } catch (System.Exception ex) { Debug.LogException(ex); } }
private void CloseNormalWin(UIWin win, bool doRefresh) { openedNormalWins.Remove(win); //remove it from normalWins if (doRefresh && !refreshing) { refreshing = true; //back to the last win if there is if (openedNormalWins.Count > 0) { //show back the last win UIWin lastWin = openedNormalWins.Last.Value; if (lastWin) { lastWin.Refresh(); lastWin.gameObject.SetActive(true); } } refreshing = false; } }
public void DoCloseWindow(UIWin win, object message = null, bool doRefresh = true) { try { if (win && IsOpen(win.ID)) { if (win.closeAnim) { win.PlayCloseAnim(() => { closeWin(win, message, doRefresh); }); } else { closeWin(win, message, doRefresh); } } } catch (System.Exception ex) { Debug.LogException(ex); } }
private void OnBack() { if (openedNormalWins.Count < 1) { return; } UIWin curWin = openedNormalWins.Last.Value; if (curWin.OnBack != null) { //custom, do on back call if (curWin.OnBack()) { curWin.OnBack = null; } } else { //default, close current window CloseWindow(openedNormalWins.Last.Value); } }
public T Open <T>(string winName, Action OnOpen = null) where T : UIWin { T win; if (winDic.ContainsKey(winName)) { Log.i("UIManager", "OpenWin", "打开已存在win winName" + winName, BeShowLog); winDic[winName].gameObject.SetActive(true); winDic[winName].OnOpen = OnOpen; winDic [winName].Open(); win = winDic[winName] as T; } else { Log.i("UIManager", "OpenWin", "打开不存在win winName" + winName, BeShowLog); var winGo = Instantiate(LoadMgr.Ins.Load(Path + winName)) as GameObject; winGo.transform.SetParent(WinTrm, false); win = winGo.GetComponent <T> (); win.OnOpen = OnOpen; CurWin = win; winDic.Add(winName, win); win.Open(); } return(win); }
/// <summary> /// open normal widow. the window will on top of other normal windows. and it will close the windows base on the target win's close type /// </summary> /// <param name="win"></param> /// <param name="onClose"></param> /// <param name="args"></param> /// <returns></returns> private void OpenNormalWin(UIWin win, Action <object> onClose = null, params object[] args) { //close other windows base on close type if (win.CloseType == UIWin.eCloseType.CloseOthers) { //close all CloseAll(); } else { //close partial int count = (int)win.CloseType; if (count > 0) { //close window for (int index = 0; index < count - 1; ++index) { LinkedListNode <UIWin> last = openedNormalWins.Last; if (last == null) { break; } //close the last openedNormalWins.RemoveLast(); doClose(last.Value); last = openedNormalWins.Last; } //hide the last LinkedListNode <UIWin> lastWin = openedNormalWins.Last; if (lastWin != null && lastWin.Value) { lastWin.Value.gameObject.SetActive(false); } } } win.CloseType = UIWin.eCloseType.Max; //reset the custom close type of win //open the win if (openedNormalWins.Contains(win)) { openedNormalWins.Remove(win); } openedNormalWins.AddLast(win); //refresh all normal window's position int i = 0; float start = (float)EUILayer.Bottom - 50; float end = (float)EUILayer.Normal; float delta = (int)(start - end) / 10; foreach (UIWin temp in openedNormalWins) { //refresh position if (temp) { temp.transform.localPosition = new Vector3(temp.transform.localPosition.x, temp.transform.localPosition.y, start - delta * i++); } else { Debug.LogError("refresh window that is null!"); } } }
/// <summary>Begins a new window! This will push a pose onto the /// transform stack, and all UI elements will be relative to that new /// pose. The pose is actually the top-center of the window. Must be /// finished with a call to UI.WindowEnd(). This override omits the /// size value, so the size will be auto-calculated based on the /// content provided during the previous frame.</summary> /// <param name="text">Text to display on the window title, should be /// unique as it will be used as the window's id.</param> /// <param name="pose">The pose state for the window! If showHeader /// is true, the user will be able to grab this header and move it /// around.</param> /// <param name="windowType">Describes how the window should be drawn, /// use a header, a body, neither, or both?</param> /// <param name="moveType">Describes how the window will move when /// dragged around.</param> public static void WindowBegin(string text, ref Pose pose, UIWin windowType = UIWin.Normal, UIMove moveType = UIMove.FaceUser) => NativeAPI.ui_window_begin(text, ref pose, Vec2.Zero, windowType, moveType);