Example #1
0
        /// <summary>
        /// コンポーネントの生成コールバック.
        /// インスタンスが生成された時に、コールされます.
        /// </summary>
        protected virtual void Awake()
        {
            //インスタンスとして登録します.
            if (m_Instance == null)
            {
                m_Instance = this as T;
            }
            //複数のインスタンスは許可しません.
            else if (m_Instance != this)
            {
                Debug.LogError(this + "," + "Multiple" + "," + typeof(T).Name + "," + "exist in scene. please fix it.");
                enabled = false;
                if (Application.isPlaying)
                {
                    Destroy(this);
                }
                return;
            }

            FitByParent(UIManager.uiRootCanvas.transform);
            argument = new UIArgument()
            {
                path = typeof(T).Name
            };
            orderTracker.ignoreParentTracker = true;
            orderTracker.addSortingOrder     = sortingOrder;
            gameObject.SetActive(false);
        }
Example #2
0
        /// <summary>
        /// Requests the dialog.
        /// </summary>
        /// <returns>The dialog.</returns>
        /// <param name="path">Path.</param>
        /// <param name="arg">Argument.</param>
        public static Coroutine RequestDialog(string path, UIArgument arg = null)
        {
            arg = arg ?? new UIArgument();
            if (!string.IsNullOrEmpty(path))
            {
                arg.path = path;
            }

            return(instance.StartCoroutine(CoShow(arg, typeof(UIDialog))));
        }
Example #3
0
        /// <summary>
        /// Requests the screen.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="arg">Argument.</param>
        /// <param name="enableResume">If set to <c>true</c> enable resume.</param>
        public static Coroutine RequestScreen(string path, UIArgument arg = null, bool enableResume = true)
        {
            arg = arg ?? new UIArgument();
            if (!string.IsNullOrEmpty(path))
            {
                arg.path = path;
            }

            if (currentScreen && currentScreen.argument.path == arg.path)
            {
                Debug.LogError("同じスクリーンをリクエストしてる!");
                return(null);
            }

            //レジューム可能なら、履歴チェック
            return((enableResume ? BackScreen(path) : null)
                   ?? instance.StartCoroutine(CoShow(arg, typeof(UIScreen))));
        }
Example #4
0
        static IEnumerator CoShow(UIArgument arg, System.Type type)
        {
            string cond = "CoShow_" + arg.path;

            UIRaycastBlocker.instance.AddCondition(cond);

            Debug.LogWarningFormat("#### CoShow stat {0}", arg.path);

            // スクリーンの場合、アウト実行
            Coroutine coHide = null;

            if (typeof(UIScreen).IsAssignableFrom(type))
            {
                // スクリーンの場合、履歴に追加
                if (!arg.isBacked)
                {
                    screenHistory.Add(arg);
                }

                // アウト実行
                // Backのばあい、サスペンドしない。
                coHide        = instance.StartCoroutine(CoHide(currentScreen, !arg.isBacked, true));
                currentScreen = null;
            }

            //キャッシュから取得.
            UIBase uiShow = GetPooledObject(arg.path, false);

            if (uiShow)
            {
                Debug.LogFormat("{1:D6} >>>> [UIM] Find Instance in Cache : {0}", arg.path, Time.frameCount);
            }
            else
            {
                //シーンロード可能.
                int index = SceneUtility.GetBuildIndexByScenePath(arg.path);
                if (0 <= index)
                {
                    //スクリーンシーンのロード開始.
                    Debug.LogFormat("{1:D6} >>>> [UIM] Load Scene : {0}", arg.path, Time.frameCount);
                    yield return(SceneManager.LoadSceneAsync(arg.path, LoadSceneMode.Additive));

                    uiShow = waitInitialize.Find(x => x && x.gameObject.scene.name == arg.path && type.IsInstanceOfType(x));

                    //ダイアログの場合、シーンは破棄.
                    if (typeof(UIDialog).IsAssignableFrom(type))
                    {
                        uiShow.transform.SetParent(null);
                        SceneManager.MoveGameObjectToScene(uiShow.gameObject, currentScreen.gameObject.scene);
                        SceneManager.UnloadSceneAsync(arg.path);
                    }
                }
                //Resourcesからロード
                else
                {
                    Debug.LogFormat("{1:D6} >>>> [UIM] Load Prefab : {0}", arg.path, Time.frameCount);
                    var req = Resources.LoadAsync <GameObject>(arg.path);
                    yield return(req);

                    var go = Object.Instantiate(req.asset, currentScreen.canvas.rootCanvas.transform) as GameObject;
                    uiShow = go.GetComponent <UIBase>();
                }
            }

            uiShow.argument = arg;

            //スクリーンの場合、カレントを変更
            if (uiShow is UIScreen)
            {
                currentScreen = uiShow as UIScreen;
                uiShow.orderTracker.ignoreParentTracker = false;

                //TODO: List使うオーバーロードに切り替え
                uiShow.gameObject.scene.GetRootGameObjects(s_TempGameObjects);
                foreach (var go in s_TempGameObjects)
                {
                    go.SetActive(true);
                }
                s_TempGameObjects.Clear();
            }
            else if (uiShow is UIDialog)
            {
                //TODO: Transformのキャッシュ
                //TODO: UIRootCanvasのキャッシュ
                uiShow.FitByParent(currentScreen.canvas.rootCanvas.transform);
                uiShow.cachedTransform.SetAsLastSibling();

                currentScreen.dialogs.Add(uiShow as UIDialog);
                (uiShow as UIDialog).screen             = currentScreen;
                uiShow.orderTracker.ignoreParentTracker = false;
            }

            yield return(instance.StartCoroutine(CoShow(uiShow, coHide)));

            UIRaycastBlocker.instance.RemoveCondition(cond);
        }