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> /// <param name="go"></param> /// <param name="showUiType"></param> /// <param name="sBaseName"></param> /// <returns></returns> private IEnumerator PlayTween(GameObject go, ShowUiType showUiType, string sBaseName) { Transform tran = go.transform.Find(sBaseName); if (tran != null) { switch (showUiType) { case ShowUiType.None: break; case ShowUiType.MinToMax: tran.localScale = Vector3.one * 0.75f; TweenScale.Begin(tran.gameObject, 0.2f, Vector3.one); break; case ShowUiType.LeftToRight: tran.localPosition = new Vector3(-650, 0, 0); TweenPosition.Begin(tran.gameObject, 0.2f, Vector3.zero); break; case ShowUiType.RightToLeft: tran.localPosition = new Vector3(650, 0, 0); TweenPosition.Begin(tran.gameObject, 0.2f, Vector3.zero); break; case ShowUiType.TopToBottom: break; case ShowUiType.BottomToTop: break; case ShowUiType.Custom: //自己加动画 break; } } yield break; }