/// <summary> /// 关闭窗口,根据窗口对象 /// </summary> /// <param name="ui"></param> public void HideUI(BaseUI ui) { if (ui != null) { if (ui.m_UIType == UIType.FariyGUI) { ui.wnd.Hide(); } else { ui.GameObject.SetActive(false); } ui.OnDisable(); } }
/// <summary> /// 根据窗口对象,显示窗口 /// </summary> /// <param name="ui"></param> /// <param name="paramList"></param> public void ShowUI(BaseUI ui, params object[] paramList) { if (ui.m_UIType == UIType.FariyGUI) { ui.wnd.Show(); } else { ui.GameObject.SetActive(true); ui.Transform.SetAsLastSibling(); } ui.OnShow(paramList); //UI的开启完毕后,关闭遮罩 SetMask(false); }
/// <summary> /// 初始化UIPrefab /// </summary> /// <param name="ui"></param> /// <param name="uiObj"></param> /// <param name="name"></param> /// <param name="resource"></param> /// <param name="paramList"></param> void InitFairyGUIPanel(BaseUI ui, string name, AssetAddress resource = AssetAddress.AssetBundle, params object[] paramList) { //添加到所有UI字典中去 if (!m_AllUIDic.ContainsKey(name)) { m_AllUIDic.Add(name, ui); } //创建一个Window ui.wnd = new FairyGUI.Window(); //设置UI的显示模式 SetUIShowMode(ui); ui.Awake(paramList); ShowUI(ui, paramList); }
//(“反向切换”属性)窗体的出栈逻辑 private void CloseUI_ReverseChange(BaseUI ui) { if (m_StackUI.Count >= 2) { //出栈处理 BaseUI topUIForms = m_StackUI.Pop(); //做隐藏处理 HideUI(topUIForms); //出栈后,下一个窗体做“重新显示”处理。 BaseUI nextUIForms = m_StackUI.Peek(); ShowUI(nextUIForms, nextUIForms.m_Params); } else if (m_StackUI.Count == 1) { //出栈处理 BaseUI topUIForms = m_StackUI.Pop(); //做隐藏处理 HideUI(topUIForms); } }
/// <summary> /// 设置UI的显示模式 /// </summary> /// <param name="ui"></param> void SetUIShowMode(BaseUI ui) { //根据不同的UI窗体的显示模式,分别作不同的加载处理 switch (ui.m_ShowMode) { case UIShowMode.Normal: //“普通显示”窗口模式 ShowUI_Normal(ui); break; case UIShowMode.ReverseChange: //需要“反向切换”窗口模式 ShowUI_ReverseChange(ui); break; case UIShowMode.HideOther: //“隐藏其他”窗口模式 ShowUI_HideOther(ui); break; default: break; } }
/// <summary> /// 关闭窗口,根据名称 /// </summary> /// <param name="name"></param> public void HideUI(string name) { BaseUI ui = FindUIByName <BaseUI>(name); HideUI(ui); }
/// <summary> /// 根据窗口名称显示窗口 /// </summary> /// <param name="name"></param> /// <param name="paramList"></param> public void ShowUI(string name, params object[] paramList) { BaseUI ui = FindUIByName <BaseUI>(name); ShowUI(ui, paramList); }
/// <summary> /// 打开UI /// </summary> /// <param name="name">注册的时候给的名称</param> /// <param name="bTop"></param> /// <param name="resource"></param> /// <param name="para1"></param> /// <param name="para2"></param> /// <param name="para3"></param> /// <returns></returns> public void OpenUI <T>(string name, Action <bool, T> callback = null, AssetAddress resource = FrameConstr.UseAssetAddress, params object[] paramList) where T : BaseUI { Debug.Log(string.Format("UIName:{0},AssetAddress:{1},paramList:{2}", name, resource, paramList)); //开启遮罩避免开启UI的时候接收了操作出现异常 SetMask(true); BaseUI ui = FindUIByName <BaseUI>(name); if (ui == null) { System.Type tp = null; if (m_RegisterDic.TryGetValue(name, out tp)) { ui = System.Activator.CreateInstance(tp) as BaseUI; ui.Init(); } else { Debug.LogError("找不到窗口对应的脚本,注册的窗口名称是:" + name); } //FGUI 用Addressable好困难,先用AssetBundle实现功能先,实现后看怎么优化让Addressable也能和FGUI融合 if (ui.m_UIType == UIType.FariyGUI) { if (!FairyGUIManager.Instance.m_PreFairyGUIList.ContainsKey(ui.UIResourceName)) { //没有预加载过的Fairy包,我们就加载这个包 if (resource == AssetAddress.AssetBundle) { string abName; if (FairyGUIManager.Instance.m_FairyGUIList.TryGetValue(ui.UIResourceName, out abName)) { AssetBundle ab = AssetBundleManager.Instance.LoadAssetBundle(abName); UIPackage.AddPackage(ab); InitFairyGUIPanel(ui, name, resource, paramList); } } else if (resource == AssetAddress.Addressable) { //string abName; //没有预加载过的Fairy包,我们就加载这个包 //if (FairyGUIManager.Instance.m_FairyGUIList.TryGetValue(ui.UIResourceName, out abName)) //{ //string desname = ui.UIResourceName + "_fui.bytes"; //Debug.Log("desname" + desname); //加载FairyGUI Package //AddressableManager.Instance.AsyncLoadResource<TextAsset>(desname, (TextAsset text) => //{ // Debug.Log("desLoadSuc"); // UIPackage.AddPackage( // text.bytes, // "BackPack", // async (string fairyname, string extension, Type type, PackageItem ite) => // { // Debug.Log($"{fairyname}, {extension}, {type.ToString()}, {ite.ToString()}"); // AddressableManager.Instance.AsyncLoadResource<Texture>(fairyname, (Texture tex) => // { // ite.owner.SetItemAsset(ite, tex, DestroyMethod.Custom); // InitFairyGUIPanel(ui, name, resource, paramList); // }); // }); //}); //} } else { //其他模式从本地加载 UIPackage.AddPackage(ui.UIResourceName); InitFairyGUIPanel(ui, name, resource, paramList); } } } else { GameObject uiObj = null; if (resource == AssetAddress.Resources) { //从resource加载UI uiObj = UnityEngine.Object.Instantiate(Resources.Load <GameObject>(ui.UIResourceName.Replace(".prefab", ""))) as GameObject; InitPrefab(ui, uiObj, name, resource, paramList); } else if (resource == AssetAddress.AssetBundle) { //从AssetBundle加载UI ObjectManager.Instance.InstantiateObjectAsync(m_UIPrefabPath + ui.UIResourceName, (string path, UnityEngine.Object obj, object[] paramArr) => { uiObj = obj as GameObject; InitPrefab(ui, uiObj, name, resource, paramList); }, LoadResPriority.RES_HIGHT, false, false); } else if (resource == AssetAddress.Addressable) { AddressableManager.Instance.AsyncInstantiate(m_UIPrefabPath + ui.UIResourceName, (GameObject obj) => { uiObj = obj; InitPrefab(ui, uiObj, name, resource, paramList); }); } } } else { //设置UI的显示模式 SetUIShowMode(ui); ShowUI(ui, paramList); } }