IEnumerator AsyncShow(Action callback) { //1:Instance UI //FIX:support this is manager multi gameObject,instance by your self. if (this.gameObject == null && string.IsNullOrEmpty(uiPath) == false) { GameObject go = null; bool _loading = true; PageMgr.delegateAsyncLoadUI(uiPath, (o) => { go = o != null ? GameObject.Instantiate(o) as GameObject : null; AnchorUIGameObject(go); Awake(go); isAsyncUI = true; _loading = false; //:animation active. Active(); //:refresh ui component. Refresh(); //:popup this node to top if need back. PageMgr.PopNode(this); if (callback != null) { callback(); } }); float _t0 = Time.realtimeSinceStartup; while (_loading) { if (Time.realtimeSinceStartup - _t0 >= 10.0f) { Debugger.LogError("[UI] WTF async load your ui prefab timeout!"); yield break; } yield return(null); } } else { //:animation active. Active(); //:refresh ui component. Refresh(); //:popup this node to top if need back. PageMgr.PopNode(this); if (callback != null) { callback(); } } }
/// <summary> /// Sync Show UI Logic /// </summary> public void Show() { //1:instance UI if (this.gameObject == null && string.IsNullOrEmpty(uiPath) == false) { GameObject go = null; if (PageMgr.delegateSyncLoadUI != null) { Object o = PageMgr.delegateSyncLoadUI(uiPath); go = o != null?GameObject.Instantiate(o) as GameObject : null; } else { go = GameObject.Instantiate(Resources.Load(uiPath)) as GameObject; } //protected. if (go == null) { Debugger.LogError("[UI] Cant sync load your ui prefab.uiPath = " + uiPath); return; } AnchorUIGameObject(go); //after instance should awake init. Awake(go); //mark this ui sync ui isAsyncUI = false; Transform bgTrans = this.transform.Find("bg"); if (bgTrans != null) { bgImg = bgTrans.GetComponent <Image>(); } m_ContentTrans = this.transform.Find("Content"); } //:animation or init when active. Active(); //:refresh ui component. Refresh(); //:popup this node to top if need back. PageMgr.PopNode(this); }