Beispiel #1
0
    public void Close()
    {
        float delay = 0;

        if (WndObject != null)
        {
            var peekaboo = WndObject.GetComponent <UiPeeKaBoo>() ?? WndObject.GetComponentInChildren <UiPeeKaBoo>();

            if (peekaboo != null)
            {
                if (peekaboo.Tweens.Length > 0)
                {
                    foreach (var t in peekaboo.Tweens)
                    {
                        foreach (var tw in t.GetComponents <UITweener>())
                        {
                            if (tw.delay + tw.duration > delay)
                            {
                                delay = tw.delay + tw.duration;
                            }

                            tw.PlayReverse();
                        }
                    }
                }
                else
                {
                    foreach (var tw in WndObject.GetComponents <UITweener>())
                    {
                        if (tw.delay + tw.duration > delay)
                        {
                            delay = tw.delay + tw.duration;
                        }

                        tw.PlayReverse();
                    }
                }
            }
        }

        MainScript.Instance.StartCoroutine(CloseInternal(delay));
    }
Beispiel #2
0
    private IEnumerator OpenAsyc(OnOpenCallBack callBack)
    {
        if (mWndObject)
        {
            GameObject.Destroy(mWndObject);
        }

        if (!WindowList.ActiveWindowList.ContainsKey(PrefabName))
        {
            WindowList.ActiveWindowList.Add(PrefabName, this);
            WindowList.ActiveWindowTypeList.Add(PrefabName, GetType());
        }


        var req = Resources.LoadAsync <GameObject>(PrefabName);

        yield return(req);

        var scale    = (req.asset as GameObject).transform.localScale;
        var position = (req.asset as GameObject).transform.localPosition;

        mWndObject = GameObject.Instantiate(req.asset) as GameObject;

        if (mWndObject == null)
        {
            Debug.LogWarning("OpenAsyc win object is null");
            yield break;
        }

        WindowHelper    = mWndObject.AddComponent <WindowHelper>();
        mWndObject.name = PrefabName;
        mWndObject.SetActive(true);
        IsLoaded = true;

        mRootUI = GameObject.Find("WindowsRoot/Camera");

        if (FullWindows.Contains(PrefabName))
        {
            mCullingMask            = Camera.main.cullingMask;
            Camera.main.cullingMask = 0;

            //var original = Resources.Load("BackgroundExtWnd") as GameObject;
            var original = Resources.Load("BackgroundExtWndTransparent") as GameObject;
            mExtBackground = NGUITools.AddChild(mRootUI, original);
        }

        WndObject.transform.parent        = mRootUI.transform;
        WndObject.transform.localPosition = position;
        WndObject.transform.localScale    = scale;

        BindUi();

        if (AUi != null)
        {
            foreach (var aUiClass in AUi)
            {
                if (aUiClass != null)
                {
                    aUiClass.Bind(WndObject, this);
                }
            }
        }

        OnOpen();

        var e = OnAsyncOpen().GetEnumerator();

        while (e.MoveNext())
        {
            yield return(e.Current);
        }

        OnStart();

        var peekaboo = WndObject.GetComponent <UiPeeKaBoo>() ?? WndObject.GetComponentInChildren <UiPeeKaBoo>();

        if (peekaboo != null)
        {
            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            if (peekaboo.Tweens.Length > 0)
            {
                foreach (var t in peekaboo.Tweens)
                {
                    foreach (var tw in t.GetComponents <UITweener>())
                    {
                        tw.PlayForward();
                    }
                }
            }
            else
            {
                foreach (var tw in WndObject.GetComponents <UITweener>())
                {
                    tw.PlayForward();
                }
            }
        }

        if (callBack != null)
        {
            callBack();
        }
    }