/// <summary> ///Get UI Panel By Name /// </summary> /// <param name="panelName"></param> /// <returns></returns> PanelInfor LoadUIPanelByName(string panelName, bool createWhenNotExit) { if (string.IsNullOrEmpty(panelName)) { Debug.Log("LoadUIPanelByName Fail , " + panelName); return(null); } UIPanelConfgInfor _confg = null; if (m_AllUIPanelConf.TryGetValue(panelName, out _confg) == false) { Debug.LogError("Loading Panel Not Exit" + panelName); return(null); } foreach (var item in m_AllInitialedPanel.Values) { if (item != null && item.m_Panel != null && item.m_Panel.name == panelName) { return(item); } } Debug.Log("LoadUIPanelByName ..This Panel Not Initial Yet.. " + panelName); PanelInfor infor = CreatePanelByConfg(_confg, createWhenNotExit); return(infor); }
PanelInfor CreatePanelByConfg(UIPanelConfgInfor confg, bool createWhenNotExit) { if (confg == null) { Debug.LogError("SetPanelAtRightPanel Fail, Parameter is null"); return(null); } Debug.Log("CreatePanelByConfg .... " + confg.PanelName); #region Create Object BaseOn confg // GameObject uiAsset = null; GameObject obj = Resources.Load <GameObject>(ConstDefine.UIPanelResourcePath + confg.PanelPath); // Manager.ins.ResourceMgr.LoadAsset(ConstDefine.UIPanelResourcePath + confg.PanelPath, (obj => // { // uiAsset = obj as GameObject; // })); //if (uiAsset == null) //{ // Debug.LogError("SetPanelAtRightPanel l Fail >>Panel Not Exit " + confg.PanelPath); // return null; //} GameObject _panelObj = GameObject.Instantiate(obj); _panelObj.name = confg.PanelName; #endregion #region GetComponent Of This Obj ,Make Sure Inherit From ViewBaseFU_EX,Then Set Local psotion And Rotation Transform root = m_AllUIRootBaseOnLevelDic[confg.m_UIPanelLevel]; if (root == null) { Debug.LogError("SetPanelAtRightPanel Fail,Root is Null"); return(null); } if (confg.m_UIPanelLevel != UIPanelLevel.FixedDirectionUI || confg.IsParentRoot) { _panelObj.transform.SetParent(root); ///,Log4Helper.Info(">>>>>>> Set to Root"); } //主UI 和 根节点UI设置 else { PanelInfor _infor = LoadUIPanelByName("UIMainCanvasView", true); if (_infor == null) { Debug.LogError("CreatePanelByConfg Fail.... UIMainCanvasView Not Exit"); _panelObj.transform.SetParent(root); } else { _panelObj.transform.SetParent(_infor.m_Panel.transform); _panelObj.transform.localScale = Vector3.one; //主要的UI if (_panelObj.name != "UIMainView") { _panelObj.transform.SetAsFirstSibling(); } Debug.Log(" CreatePanelByConfg. MainMenu.." + _panelObj.gameObject.name); } } //根据UI类型设置不同的父节点 ViewBaseFU_EX _view = _panelObj.transform.GetComponent <ViewBaseFU_EX>(); if (_view == null) { Debug.LogError("CreatePanelByConfg Fail..Miss ViewBaseFU_EX :" + _panelObj.name); return(null); } //Set Panel At Confg Position And Rotation _panelObj.transform.localPosition = _view.m_InitialPosition; _panelObj.transform.localEulerAngles = _view.m_InitialAngle; #endregion #region Check And Record This Panel At m_AllInitialedPanel Type type = _view.GetType(); PanelInfor infor = new PanelInfor(_panelObj, _view); if (m_AllInitialedPanel.ContainsKey(type) == false) { m_AllInitialedPanel.Add(type, infor); //Record } else if (m_AllInitialedPanel[type] == null || m_AllInitialedPanel[type].m_Panel == null) { Debug.Log("CreatePanelByConfg , Object Destroyed ,Record Now " + confg.PanelName); m_AllInitialedPanel.Remove(type); m_AllInitialedPanel.Add(type, infor); //Record } else { m_AllInitialedPanel[type] = infor; //Record } #endregion _panelObj.gameObject.SetActive(false); return(infor); }