private List <string> _listOpenView = new List <string>(); //存储所有打开的视图 /// <summary> /// 显示同步加载的界面 /// </summary> /// <param name="sPath">资源路径</param> /// <param name="showUiType">界面的打开方式</param> /// <param name="nDepth">0使用默认的安排的深度,否则使用传入的深度</param> /// <param name="objData">界面打开时带入数据</param> /// <param name="sBaseName">执行动画的对象</param> public GameObject ShowSync(string sPath, ShowUiType showUiType, int nDepth = 0, object objData = null, string sBaseName = "Base") { if (_listOpenView.Contains(sPath)) { Log.DebugError("界面已经被打开!"); return(null); } //设置对象 GameObject goView = null; if (_dicAllView.ContainsKey(sPath)) { goView = _dicAllView[sPath]; } else { goView = MgrAsset.Instance.LoadGameObjectSync(sPath); _dicAllView.Add(sPath, goView); } goView.SetActive(true); goView.transform.SetParent(GameObject.Find("UIRoot").transform); goView.transform.localScale = Vector3.one; goView.transform.localPosition = Vector3.zero; //添加界面 AddOpenView(sPath, goView); //带入数据 if (objData != null) { ExtendMonoBehaviour emb = goView.GetComponent <ExtendMonoBehaviour>(); if (emb != null) { emb.DoSetData(objData); } } //更新层级 if (nDepth == 0) { nDepth = _nMinDepth + _listOpenView.Count * _nRangeDepth; } goView.GetComponent <UIPanel>().depth = nDepth; IMgrDepth mgr = goView.GetComponent <IMgrDepth>(); if (mgr != null) { mgr.SetPanelDepth(nDepth); } //设置动画 StartCoroutine(PlayTween(goView, showUiType, sBaseName)); return(goView); }
/// <summary> /// 强制顺序更新所有界面层级 /// </summary> public void UpdateDepth() { for (var i = 0; i < _listOpenView.Count;) { string sPath = _listOpenView[i]; GameObject go = _dicOpenView[sPath]; if (go == null) { _listOpenView.Remove(sPath); _dicOpenView.Remove(sPath); } else { int nDepth = _nMinDepth + _listOpenView.Count * _nRangeDepth; go.GetComponent <UIPanel>().depth = nDepth; IMgrDepth mgr = go.GetComponent <IMgrDepth>(); if (mgr != null) { mgr.SetPanelDepth(nDepth); } } } }