/// <summary> /// 根据UI的ID显示UI /// </summary> /// <param name="id"></param> public virtual void ShowUI <T>(T id) { Transform uiTrans = SpawnUI(id.ToString()); AUIBase ui = uiTrans.GetComponent <AUIBase>(); if (ui == null) { throw new Exception("Can't find AUIBase component"); } if (ui.GetLayer() == UILayer.BasicUI) { UIHandler newHandler = new UIHandler(ui); if (uiStack.Count > 0) { uiStack.Peek().Hide(ui.GetLayer()); } AddListener(ui, id.ToString(), newHandler); newHandler.Show(ui); uiStack.Push(newHandler); } else { AddListener(ui, id.ToString(), uiStack.Peek()); uiStack.Peek().Show(ui); } }
/// <summary> /// 添加对UI的监听 /// </summary> /// <param name="ui"></param> /// <param name="initAction"></param> /// <param name="activeAction"></param> public void AddListener(AUIBase ui, Func <Object, bool> initAction, Func <bool, bool> activeAction) { if (ui.UIState == UIStateEnum.NOTINIT) { ui.AddInitListener(initAction); ui.AddActiveListener(activeAction); } }
public UIHandler(AUIBase basicUI) { if (basicUI != null) { data = new UIData((BasicUI)basicUI); } else { throw new Exception("basicUI is null"); } }
/// <summary> /// 显示UI的处理方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ui"></param> /// <param name="stack"></param> private void ShowUI <T>(AUIBase ui, Stack <T> stack = null) where T : AUIBase { if (stack != null) { if (stack.Count > 0) { stack.Peek().UIState = UIStateEnum.HIDE; } stack.Push((T)ui); } ui.UIState = UIStateEnum.SHOW; }
/// <summary> /// 显示UI /// </summary> /// <param name="ui"></param> public void Show(AUIBase ui) { switch (ui.GetLayer()) { case UILayer.BasicUI: ShowUI <BasicUI>(ui); break; case UILayer.OverlayUI: ShowUI(ui, data.OverlayUIStack); break; case UILayer.TopUI: ShowUI(ui, data.TopUIStack); break; } }
/// <summary> /// 设置UI到其对应的层级父物体下 /// </summary> /// <param name="ui"></param> public void SetUILayer(AUIBase ui) { ui.transform.SetParent(UILayerObjDic[ui.GetLayer()].transform); }
/// <summary> /// 通过UIHandler统一添加UI对UIInitAction及UIActiveAction的监听 /// </summary> /// <param name="ui"></param> /// <param name="id"></param> /// <param name="handler"></param> private void AddListener(AUIBase ui, string id, UIHandler handler) { handler.AddListener(ui, ob => UIInitAction(id.ToString(), ob), isActive => UIActiveAction(id.ToString(), isActive)); }