Exemplo n.º 1
0
    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();
            }
        }
    }