/// <summary> /// 隐藏UI界面 /// </summary> /// <param name="ui"></param> public void Hide(UIInstanceIDEnum uiInstanceID) { if (m_AllRegisterUI.Contains(uiInstanceID)) //如果界面有注册 { if (m_AllInstantiateUI.ContainsKey(uiInstanceID)) //如果界面生成过 { BaseUIView view = m_AllInstantiateUI[uiInstanceID].View; view.OnHide(); BaseUIController controller = view.GetComponent <BaseUIController>(); controller.OnHide(); view.gameObject.SetActive(false); } } else { LogManager.LogError("显示没有注册的界面:" + uiInstanceID); } }
/// <summary> /// 显示UI /// </summary> /// <param name="uiInstanceID">UI唯一实例ID</param> /// <param name="uiGameObject">UI界面游戏物体</param> /// <param name="args">传递参数</param> public void ShowUI(UIInstanceIDEnum uiInstanceID, object args = null) { if (m_AllRegisterUI.Contains(uiInstanceID)) //如果界面有注册 { if (!m_AllInstantiateUI.ContainsKey((UIInstanceIDEnum)uiInstanceID)) //如果界面没有生成过 { //根据界面枚举找到对应加载预制体的路径 //todo:这边应该是配置单独的模块进行配置加载和读取,而不是和其他关联 //if (FarmGameManager.Instance.m_UIPathConfig == null) //{ // LogManager.LogError("没有读取到界面配置"); // return; //} //foreach (var item in FarmGameManager.Instance.m_UIPathConfig.allUIPath) //{ // if (item.id == (int)uiInstanceID) // { // LogManager.Log("path=" + item.path); // GameObject uiGameObject = ResourceLoadManager.Instance.Load(item.path) as GameObject; // BaseUIView view = Instantiate(uiGameObject).GetComponent<BaseUIView>(); // view.UIInstanceID = (int)uiInstanceID; // view.OnCreated(args); // view.OnShow(args); // BaseUIController controller = view.GetComponent<BaseUIController>(); // controller.OnCreated(args); // controller.OnShow(args); //todo:在这边也进行model层的初始化 // m_AllInstantiateUI.Add((UIInstanceIDEnum)view.UIInstanceID, controller); // } //} } else//已经生成过界面 { BaseUIView view = m_AllInstantiateUI[uiInstanceID].View; view.OnShow(args); BaseUIController controller = view.GetComponent <BaseUIController>(); controller.OnShow(args); } } else { LogManager.LogError("显示没有注册的界面:" + uiInstanceID); } }