public void Close(Panel p) { if (p.Container != null && p.Container != this) { p.Container.Close(p); return; } if (CurrentPanelStack.m_homePanel == p) { PopTo(CurrentPanelStack, null); PopStack(); return; } PanelStack stack = null; if (m_pushedPanelStacks.TryGetValue(p, out stack)) { PopTo(stack, null); } else { Hide(p, true, p.PopAnimation); } }
public void PopStack(string stackName) { PanelStack stack = null; if (m_namedStacks.TryGetValue(stackName, out stack)) { PopStack(stack); } }
/// <summary> /// 销毁UI面板 /// </summary> /// <param name="panel">销毁指定的UI面板</param> public void DestoryPanel(BaseUIPanel panel) { UIPanleList.Remove(panel); if (PanelStack.Contains(panel)) { RemovePanel_in_Stack(panel); } Object.Destroy(panel); }
/// <summary> /// 从当前层移除一个面板 /// </summary> /// <param name="panelType"></param> public void RemovePanel(PanelType panelType) { Debug.Log($"移除了一个{panelType}面板"); if (TryGetPanel(panelType, out BasePanel panel)) { PanelStack.Peek().Remove(panel); panel.OnExit(); } }
public void PushStack(string name, object data = null, Action onClose = null) { PanelStack stack = null; if (m_namedStacks.TryGetValue(name, out stack)) { PushStack(stack, data, onClose); } }
/// <summary> /// 在当前层添加一个面板 /// </summary> /// <param name="panelType"></param> public void AddPanel(PanelType panelType) { if (PanelStack.Any()) { if (TryGetPanel(panelType, out BasePanel panel)) { PanelStack.Peek().Add(panel); panel.OnEnter(); } } }
public void Push(string stackName, Panel p, object data, Action onClose = null, bool animate = true) { if (p.Container != null && p.Container != this) { p.Container.Push(stackName, p, data, onClose, animate); return; } PanelStack stack = null; if (CurrentPanelStack == null && string.IsNullOrEmpty(stackName)) { stackName = DefaultStackName; } if (!string.IsNullOrEmpty(stackName)) { m_namedStacks.TryGetValue(stackName, out stack); } else { stack = CurrentPanelStack; } if (stack == null) { AddStack(stackName, null); stack = m_namedStacks[stackName]; } var curr = CurrentPanel; if (curr && curr.Modal) { // This prevents other panels from pre-empting the current one var call = curr.OnClose; curr.OnClose = () => { if (call != null) { call(); } PushPanel(stack, p, data, onClose, animate); }; } else { PushPanel(stack, p, data, onClose, animate); } }
/// <summary> /// 显示最顶部的UI面板 /// </summary> public void ShowPanel() { var UIPanel = PanelStack.Peek(); if (UIPanel.Panel_Type == PanelType.Subclass) { if (!PanelStack.Contains(UIPanel)) { PanelStack.Push(UIPanel); } TakePanelToTop(UIPanel); } }
public void PopTo(Panel p) { PanelStack stack = null; if (p != null && m_pushedPanelStacks.TryGetValue(p, out stack)) { PopTo(stack, p); } else { PopTo(CurrentPanelStack, p); } }
private void Awake() { instance = this; if (basePanel == null) { Debug.LogError("PanelStack must have a base panel defined"); return; } Panels.Add(basePanel); foreach (var panel in GetComponentsInChildren <Panel>(true)) { panel.gameObject.SetActive(panel == basePanel); } }
void PopTo(PanelStack stack, Panel p) { for (int i = stack.m_panels.Count - 1; i >= 0; i--) { if (p == stack.CurrentPanel) { return; } var toPop = stack.m_panels[i]; PopPanel(stack, toPop, (i == stack.m_panels.Count - 1), toPop.ExitAnimation ? toPop.ExitAnimation : toPop.PopAnimation); } }
/// <summary> /// 显示UI面板 /// </summary> /// <param name="UIPanel">指定被显示的UI面板</param> public void ShowPanel(BaseUIPanel UIPanel) { if (!UIPanel) { Debug.LogError("错误!,缓存中找不到该Panel"); return; } //PanelStack.Push(UIPanel); if (!PanelStack.Contains(UIPanel)) { PanelStack.Push(UIPanel); } TakePanelToTop(UIPanel); //UIPanel.gameObject.SetActive(true); }
/// <summary> /// 显示UI面板 /// </summary> /// <param name="PanelName">UI面板的名称</param> public void ShowPanel(string PanelName) { var UIPanel = GetPanel(PanelName); if (!UIPanel) { CreateUIPanel(PanelName, PanelType.Singleton); return; } if (!PanelStack.Contains(UIPanel)) { PanelStack.Push(UIPanel); } TakePanelToTop(UIPanel); //if (UIPanel) UIPanel.gameObject.SetActive(true); }
/// <summary> /// 移除最上层所有面板 /// </summary> public void PopPanel() { if (PanelStack.Any()) { foreach (var panel in PanelStack.Pop()) { panel.OnExit(); } if (PanelStack.Any()) { foreach (var panel in PanelStack.Peek()) { panel.OnResume(); } } } }
/// <summary> /// 推入一个面板并置于新的一层 /// </summary> /// <param name="panelType"></param> public void PushPanel(PanelType panelType) { if (TryGetPanel(panelType, out BasePanel panel)) { //将当前层隐藏,再推入新的一层 if (PanelStack.Any()) { foreach (var item in PanelStack.Peek()) { item.OnPause(); } } PanelStack.Push(new HashSet <BasePanel> { panel }); panel.OnEnter(); } }
void PushStack(PanelStack stack, object data = null, Action onClose = null) { if (CurrentPanelStack != stack && CurrentPanelStack.CurrentPanel) { CurrentPanelStack.CurrentPanel.DidResignTop(); SetPanelActive(CurrentPanelStack.CurrentPanel, false); } if (stack.m_homePanel) { stack.m_homePanel.OnClose = onClose; SetPanelActive(stack.m_homePanel, true); stack.m_homePanel.SetReady(true); stack.m_homePanel.DidPush(data); } m_panelStacks.Add(stack); }
public override void OnHidePanel(UIPanelId panelId, InternalUIPanel panel) { if (stack.Count <= 0) { return; } PanelStack panelStack = stack.Peek(); //栈顶界面关闭 if (panelStack.panelId == panelId) { //就剩一个了 if (stack.Count <= 1) { return; } stack.Pop(); PanelStack nextPanel = stack.Peek(); UILocate.UI.Show(nextPanel.panelId); } }
protected readonly string UIPanlePath = "UIPanel/"; //UI面板存放的路径,所有的UI面板都会从此路径创建 /// <summary> /// 检查所有UI面板的状态 /// </summary> private void CheckPanelState() { if (PanelStack.Count <= 0) { return; } TopPanel = PanelStack.First(); TopPanel.gameObject.SetActive(true); TopPanel.Panel_State = PanelState.Show; TopPanel.StartCheck(); foreach (var VARIABLE in UIPanleList) { if (VARIABLE.Panel_Index != TopPanel.Panel_Index) { if (VARIABLE.Panel_State != PanelState.Pause) { VARIABLE.Panel_State = PanelState.Pause; VARIABLE.OnPause(); } } } }
void PopPanel(Panel p, bool animate = true, RuntimeAnimatorController animController = null) { if (p == CurrentPanelStack.m_homePanel) { PopStack(); return; } PanelStack stack = null; if (m_pushedPanelStacks.TryGetValue(p, out stack)) { PopPanel(stack, p, animate, animController); } else { m_logger.Error("Popping panel without a stack: {0}", p.GetType().ToString(), string.Join(",", m_pushedPanelStacks.Keys.Select(k => k.name).ToArray()) ); } }
/// <summary> /// 显示UI面板 /// </summary> /// <param name="PanelName">UI面板的名称</param> /// <param name="type">UI面板的类型</param> public void ShowPanel(string PanelName, PanelType type) { switch (type) { case PanelType.Subclass: CreateUIPanel(PanelName, type); break; default: var UIPanel = GetPanel(PanelName) ?? null; if (UIPanel == null) { CreateUIPanel(UIPanel); } if (!PanelStack.Contains(UIPanel)) { PanelStack.Push(UIPanel); } TakePanelToTop(UIPanel); //UIPanel.gameObject.SetActive(true); break; } }
protected virtual void Awake() { DefaultOrientation = Screen.orientation; m_panelStacks = new List <PanelStack>(); var mainStack = new PanelStack(DefaultStackName, RootPanel); m_panelStacks.Add(mainStack); m_namedStacks = new Dictionary <string, PanelStack> { { DefaultStackName, mainStack } }; m_pushedPanelStacks = new Dictionary <Panel, PanelStack>(); m_showPanels = new HashSet <Panel>(); m_logger = new Logger(this); var allPanels = GetComponentsInChildren <Panel>(true); m_panelTypeDict = new Dictionary <Type, Panel>(); m_panelNameDict = new Dictionary <string, Panel>(); foreach (var panel in allPanels) { m_panelTypeDict[panel.GetType()] = panel; m_panelNameDict[panel.gameObject.name.TrimEnd()] = panel; if (AttachAllChildPanels && !panel.Container) { panel.Container = this; } } ObjectHelper.SetObjectsActive(ShowWhenPanelsShowing, false); ObjectHelper.SetObjectsActive(ShowWhenNoPanelsShowing, true); }
public void Pop(Panel p, bool popPanelsOnTop) { PanelStack stack = null; if (p.Container != null && p.Container != this) { p.Container.Pop(p); return; } if (m_pushedPanelStacks.TryGetValue(p, out stack)) { if (popPanelsOnTop) { PopTo(stack, p); } PopPanel(stack, p, true, p.PopAnimation); } else { Hide(p, true, p.PopAnimation); } }
void PopStack(PanelStack stack) { m_panelStacks.Remove(stack); PopTo(stack, null); if (stack.m_homePanel) { stack.m_homePanel.DidPop(); SetPanelActive(stack.m_homePanel, false); if (stack.m_homePanel.OnClose != null) { stack.m_homePanel.OnClose(); } } // Reactivate the top panel in the current stack stack if (CurrentPanel) { SetPanelActive(CurrentPanel, true); } }
public void PushStack(Panel homePanel = null, object data = null, Action onClose = null) { PanelStack stack = new PanelStack("<anonymous>", homePanel); PushStack(stack, data, onClose); }
void PopPanel(PanelStack panelStack, Panel p, bool animate = true, RuntimeAnimatorController animController = null) { bool isTop = (p == panelStack.CurrentPanel); // Can only call PopPanel on the top panel /* rc - 11/28/2017: let panels get "popped" from * the middle of a stack. Most of the time the opposite * behaviour is unwanted (a middle panel taking anything that was * pushed after with it) * if (p != panelStack.CurrentPanel) * { * return; * }*/ AnalyticsHelper.FireEvent("PopPanel", new Dictionary <string, object> { { "Name", p.GetType().ToString() } }); m_logger.Debug("PopPanel {0} ({1}) stack={2} start", p.name, p.GetType().Name, panelStack.m_stackName); panelStack.Remove(p); m_pushedPanelStacks.Remove(p); m_showPanels.Remove(p); var curr = panelStack.CurrentPanel; var onClose = p.OnClose; p.OnClose = null; if (onClose != null) { onClose(); } if (!isTop) { // Skip animations, etc. The code // after this conditional is only // applicable when popping the top // panel SetPanelActive(p, false); p.DidPop(); return; } // If the current top panel is the one that we remembered // from before. This handles the case that "onClose" caused // the same panel to be pushed again (e.g. screen message -> // screen message) if (panelStack.CurrentPanel && (panelStack.CurrentPanel == curr)) { m_logger.Verbose("PopPanel from {0} -> {1} is ready={2}", p.GetType().Name, panelStack.CurrentPanel.GetType().Name, panelStack.CurrentPanel.IsReady); SetPanelActive(panelStack.CurrentPanel, true); panelStack.CurrentPanel.DidRegainTop(); } SetPanelOrientation(curr); // Hide this panel last // We might be re-showing the same panel as part of the onClose flow, // if so, don't tell the panel it hid because this will shut the panel down. if (panelStack.CurrentPanel != p) { Action doPop = () => { var animCtl = animController ?? p.PopAnimation; if (animCtl && animate) { p.DoAnimation(animCtl); } else { SetPanelActive(p, false); } p.DidPop(); }; if (panelStack.CurrentPanel && !panelStack.CurrentPanel.IsReady) { m_logger.Verbose("Current panel {0} is not ready!", panelStack.CurrentPanel.name); p.transform.SetAsLastSibling(); StartCoroutine(CallWhenReady(panelStack.CurrentPanel, () => { // Make sure the panel we're disabling didn't become the // current panel if (p != panelStack.CurrentPanel) { doPop(); } })); } else { m_logger.Verbose("Current panel {0} is ready!", panelStack.CurrentPanel ? panelStack.CurrentPanel.name : null); doPop(); } } if (m_showPanels.Count == 0) { ObjectHelper.SetObjectsActive(ShowWhenPanelsShowing, false); ObjectHelper.SetObjectsActive(ShowWhenNoPanelsShowing, true); } m_logger.Verbose("PopPanel {0} end", p.GetType().Name); }
void PushPanel(PanelStack stack, Panel p, object data, Action onClose, bool animate = true) { AnalyticsHelper.FireEvent("PushPanel", new Dictionary <string, object> { { "Name", p.GetType().ToString() } }); PanelStack currStack = null; m_pushedPanelStacks.TryGetValue(p, out currStack); if (currStack != null && currStack != stack) { m_logger.Error("Panel {0} already in another stack (curr={1} requested={2}), aborting push", p.GetType().Name, currStack.m_stackName, stack.m_stackName); return; } m_pushedPanelStacks[p] = stack; m_logger.Debug("PushPanel {0} ({1}) stack={1} start", p.name, p.GetType().Name, stack.m_stackName); var curr = stack.CurrentPanel; if (curr == p) { // This panel is already showing, don't go any further. m_logger.Debug("PushPanel {0} stack={1} already on top", p.GetType().Name, stack.m_stackName); p.OnClose = onClose; p.DidPush(data); return; } if (curr) { m_logger.Verbose("PushPanel curr = {0}", curr.GetType().Name); var anim = curr.GetAnimationTarget().GetComponent <Animator>(); if (anim && curr.IsReady) { // Review this: if we remove the animator controller // before it finishes its animation, we can end up // in a situation where the panel is hidden or partially // occluded. // Only set it null if it's marked as "ready". This // indicates that the animation has completed. //anim.runtimeAnimatorController = null; //Destroy(anim); anim.enabled = false; } if (StackBehavior == PanelStackBehavior.Normal) { curr.DidResignTop(); if (!curr.KeepActiveInStack) { SetPanelActive(curr, false); } } else if (StackBehavior == PanelStackBehavior.OneAtATime) { PopPanel(stack, curr); } } p.SetReady(false); // Remove this one from the stack if it's already there stack.m_panels.Remove(p); stack.m_panels.Add(p); p.OnClose = onClose; DoShowPanel(p, animate); p.DidPush(data); m_logger.Verbose("PushPanel {0} end", p.GetType().Name); }
public void AddStack(string name, Panel homePanel) { var stack = new PanelStack(name, homePanel); m_namedStacks.Add(name, stack); }