Ejemplo n.º 1
0
        /// <summary>
        /// Set Selectable
        /// </summary>
        /// <param name="identifiers">UiIdentifiers</param>
        // -------------------------------------------------------------------------------------
        public static void setSelectable()
        {
#if UNITY_IOS || UNITY_ANDROID
            EventSystem.current.SetSelectedGameObject(null);
            return;
#else
            // -----------------

            Selectable commonUiSelectable           = CommonUiManager.Instance.getDefaultSelectableFromCurrentShowingUi();
            Selectable sceneUiSelectable            = (SceneUiManager.isAvailable()) ? SceneUiManager.Instance.getDefaultSelectableFromCurrentShowingUi() : null;
            GameObject currentGameObject            = EventSystem.current.currentSelectedGameObject;
            bool       nowInShowingTransitionCommon = CommonUiManager.Instance.m_nowInShowingTransition;
            bool       nowInShowingTransitionScene  = (SceneUiManager.isAvailable()) ? SceneUiManager.Instance.m_nowInShowingTransition : false;

            if (nowInShowingTransitionCommon || nowInShowingTransitionScene)
            {
                return;
            }

            // --------------------

            {
                if (commonUiSelectable)
                {
                    if (currentGameObject != commonUiSelectable.gameObject)
                    {
                        commonUiSelectable.Select();
                    }
                }

                else if (sceneUiSelectable)
                {
                    if (currentGameObject != sceneUiSelectable.gameObject)
                    {
                        sceneUiSelectable.Select();
                    }
                }

                else
                {
                    EventSystem.current.SetSelectedGameObject(null);
                }
            }
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send pause state if needed
        /// </summary>
        // -------------------------------------------------------------------------------------
        protected static void sendPauseSignalIfNeeded()
        {
            bool temp = false;

            temp = temp || CommonUiManager.Instance.shouldSendPauseState();

            if (SceneUiManager.isAvailable())
            {
                temp = temp || SceneUiManager.Instance.shouldSendPauseState();
            }

            var pState = SimpleReduxManager.Instance.PauseStateWatcher.state();

            if (temp != pState.pause)
            {
                pState.setState(SimpleReduxManager.Instance.PauseStateWatcher, temp);
            }
        }
        /// <summary>
        /// If an instance already exists, destroy new one.
        /// </summary>
        /// <returns>if instance is this, return true.</returns>
        //-----------------------------------------------------------------------
        bool checkInstance()
        {
            if (instance == null)
            {
                instance = (SceneUiManager)this;
                return(true);
            }
            else if (Instance == this)
            {
                return(true);
            }


#if UNITY_EDITOR
            Debug.LogWarning("(#if UNITY_EDITOR) Destroy the object because an instance alresdy exists : " + this.gameObject.name);
#endif
            Destroy(this.gameObject);

            return(false);
        }
        // -------------------------------------------------------------------------------------------------------
        protected IEnumerator startNowLoadings(ResumePoint resumePoint)
        {
            yield return(null);

            // wait by lock
            {
                int i = 0;

                while (this.m_lockBeforeLoadings.Count > 0)
                {
                    yield return(null);

                    for (i = this.m_lockBeforeLoadings.Count - 1; i >= 0; i--)
                    {
                        if (!this.m_lockBeforeLoadings[i])
                        {
                            this.m_lockBeforeLoadings.RemoveAt(i);
                        }
                    }
                }
            }

            // unload
            if (resumePoint == ResumePoint.None)
            {
                AsyncOperation ao = Resources.UnloadUnusedAssets();

                while (!ao.isDone)
                {
                    yield return(null);
                }

                System.GC.Collect();
            }

            // SceneChangeStateWatcher
            {
                if (resumePoint == ResumePoint.None)
                {
                    var scState = SimpleReduxManager.Instance.SceneChangeStateWatcher.state();
                    scState.setState(SimpleReduxManager.Instance.SceneChangeStateWatcher, SceneChangeState.StateEnum.NowLoadingMain);
                }
            }

            // load
            if (resumePoint == ResumePoint.None)
            {
                if (!this.m_loadingScenesProgress.ContainsKey(this.m_nowLoadingSceneName))
                {
                    this.m_loadingScenesProgress.Add(this.m_nowLoadingSceneName, 0.0f);
                }

                AsyncOperation ao = SceneManager.LoadSceneAsync(this.m_nowLoadingSceneName);

                if (ao == null)
                {
                    Invoke("showBackToTitleOkDialog", 0.1f);
                    yield break;
                }

                while (!ao.isDone)
                {
                    this.m_loadingScenesProgress[this.m_nowLoadingSceneName] = ao.progress;
                    yield return(null);
                }

                this.m_loadingScenesProgress[this.m_nowLoadingSceneName] = 1.0f;
            }

            // main
            {
                bool sceneAdditiveDetected = false;
                bool needToReload          = false;

                System.Object messages = null;

                do
                {
                    sceneAdditiveDetected = false;

                    // IEnumeratorStartupManager Before
                    if (resumePoint <= ResumePoint.IEBefore)
                    {
                        yield return(IEnumeratorStartupManager.Instance.startIEnumerator(IEnumeratorStartupManager.BeforeAfter.Before));

                        if (IEnumeratorStartupManager.Instance.hasError())
                        {
                            messages           = IEnumeratorStartupManager.Instance.createErrorMessage();
                            this.m_resumePoint = ResumePoint.IEBefore;
                            break;
                        }
                    }

                    // AssetBundleStartupManager
                    if (resumePoint <= ResumePoint.AssetBundle)
                    {
                        List <AssetBundle> additiveScenes = new List <AssetBundle>();

                        yield return(AssetBundleStartupManager.Instance.startAbStartup(
                                         this.m_loopCounterForABStartup++ > 0,
                                         (detectedAdditiveScenes) =>
                        {
                            additiveScenes.AddRange(detectedAdditiveScenes);
                        },
                                         (reload) =>
                        {
                            needToReload = reload;
                        }));

                        if (AssetBundleStartupManager.Instance.hasError())
                        {
                            messages           = AssetBundleStartupManager.Instance.createErrorMessage();
                            this.m_resumePoint = ResumePoint.AssetBundle;
                            break;
                        }

                        if (needToReload)
                        {
                            break;
                        }

                        if (additiveScenes.Count > 0)
                        {
                            sceneAdditiveDetected = true;

                            for (int i = additiveScenes.Count - 1; i >= 0; i--)
                            {
                                AssetBundle ab = additiveScenes[i];

                                foreach (string str in ab.GetAllScenePaths())
                                {
                                    if (!this.m_loadingScenesProgress.ContainsKey(str))
                                    {
                                        this.m_loadingScenesProgress.Add(str, 0.0f);
                                    }

                                    var aoForAdditive = SceneManager.LoadSceneAsync(Path.GetFileNameWithoutExtension(str), LoadSceneMode.Additive);

                                    while (!aoForAdditive.isDone)
                                    {
                                        this.m_loadingScenesProgress[str] = aoForAdditive.progress;
                                        yield return(null);
                                    }

                                    this.m_loadingScenesProgress[str] = 1.0f;
                                }

                                ab.Unload(false);
                            }

                            continue;
                        }
                    }

                    // WwwStartupManager
                    if (resumePoint <= ResumePoint.Www)
                    {
                        yield return(WwwStartupManager.Instance.startWwwStartup());

                        if (WwwStartupManager.Instance.hasError())
                        {
                            messages           = WwwStartupManager.Instance.createErrorMessage();
                            this.m_resumePoint = ResumePoint.Www;
                            break;
                        }
                    }

                    // IEnumeratorStartupManager After
                    if (resumePoint <= ResumePoint.IEAfter)
                    {
                        yield return(IEnumeratorStartupManager.Instance.startIEnumerator(IEnumeratorStartupManager.BeforeAfter.After));

                        if (IEnumeratorStartupManager.Instance.hasError())
                        {
                            messages           = IEnumeratorStartupManager.Instance.createErrorMessage();
                            this.m_resumePoint = ResumePoint.IEAfter;
                            break;
                        }
                    }
                } while (sceneAdditiveDetected);

                if (messages != null)
                {
                    DialogManager.Instance.showYesNoDialog(messages, this.retry, this.showBackToTitleOkDialog);
                    yield break;
                }

                if (needToReload)
                {
                    Invoke("callbackWhenShowingNowLoadingDone", 0.1f);
                    yield break;
                }

                //
                {
                    if (IEnumeratorStartupManager.Instance.checkIfDetectedNewStartup(IEnumeratorStartupManager.BeforeAfter.Before))
                    {
                        this.m_resumePoint = ResumePoint.IEBefore;
                        Invoke("retry", 0.1f);
                        yield break;
                    }

                    else if (AssetBundleStartupManager.Instance.checkIfDetectedNewStartup())
                    {
                        this.m_resumePoint = ResumePoint.AssetBundle;
                        Invoke("retry", 0.1f);
                        yield break;
                    }

                    else if (WwwStartupManager.Instance.checkIfDetectedNewStartup())
                    {
                        this.m_resumePoint = ResumePoint.Www;
                        Invoke("retry", 0.1f);
                        yield break;
                    }

                    else if (IEnumeratorStartupManager.Instance.checkIfDetectedNewStartup(IEnumeratorStartupManager.BeforeAfter.After))
                    {
                        this.m_resumePoint = ResumePoint.IEAfter;
                        Invoke("retry", 0.1f);
                        yield break;
                    }
                }
            }

            // SceneChangeStateWatcher
            {
                yield return(null);

                var scState = SimpleReduxManager.Instance.SceneChangeStateWatcher.state();
                scState.setState(SimpleReduxManager.Instance.SceneChangeStateWatcher, SceneChangeState.StateEnum.AllStartupsDone);
                yield return(null);
            }

            // wait by lock
            {
                int i = 0;

                while (this.m_lockAfterLoadings.Count > 0)
                {
                    yield return(null);

                    for (i = this.m_lockAfterLoadings.Count - 1; i >= 0; i--)
                    {
                        if (!this.m_lockAfterLoadings[i])
                        {
                            this.m_lockAfterLoadings.RemoveAt(i);
                        }
                    }
                }
            }

            // SceneChangeStateWatcher
            {
                var scState = SimpleReduxManager.Instance.SceneChangeStateWatcher.state();
                scState.setState(SimpleReduxManager.Instance.SceneChangeStateWatcher, SceneChangeState.StateEnum.NowLoadingOutro);
            }

            // show ui
            {
                if (SceneUiManager.isAvailable())
                {
                    if (this.m_sceneUiIdentifiersAfterLoadingScene.Count > 0)
                    {
                        SceneUiManager.Instance.showUi(this.m_sceneUiIdentifiersAfterLoadingScene, true, false, 0, null, null);
                    }
                    CommonUiManager.Instance.showUi(this.m_commonUiIdentifiersAfterLoadingScene, true, false, 0, this.sendNowLoadingDoneSignal, null);
                }

                else
                {
                    CommonUiManager.Instance.showUi(this.m_commonUiIdentifiersAfterLoadingScene, true, false, 0, this.sendNowLoadingDoneSignal, null);
                }
            }

            // clear
            {
                this.clearContents();
            }
        }