Beispiel #1
0
        /// <summary>
        /// Creates a default loading spinner, and then modifies it for the
        /// ProjectNavigator's purposes.  It should not be passed to the
        /// SceneNavigator; it will directly register for the events so that
        /// it can control its own visibility.  Specifically, it stays
        /// visible until the second 'will in' transition.
        /// </summary>
        /// <returns>The loading spinner.</returns>
        private LoadingSpinner CreateLoadingSpinner(GameObject loadingSpinnerPrefab = null, System.Func <int> updateProgressImpl = null)
        {
            LoadingSpinner loadingSpinner = null;

            if (loadingSpinnerPrefab)
            {
                GameObject go = Instantiate(loadingSpinnerPrefab);
                go.SetActive(false);
                loadingSpinner = go.GetComponentInChildren <LoadingSpinner>();
                if (!loadingSpinner)
                {
                    Destroy(go);
                }
            }
            loadingSpinner = loadingSpinner ?? LoadingSpinner.Create();
            loadingSpinner.transform.parent = this.transform;
            foreach (var layout in loadingSpinner.GetComponentsInChildren <SagoLayout.LayoutComponent>())
            {
                layout.ApplyOnUpdate = true;
            }

            if (updateProgressImpl != null)
            {
                loadingSpinner.IsProgressTextEnabled = true;
                loadingSpinner.UpdateProgressImpl   += updateProgressImpl;
            }
            else
            {
                loadingSpinner.IsProgressTextEnabled = false;
            }

            bool allowShutdown = false;

            System.Action <SceneController, SceneTransition> onDidOut = null;
            onDidOut = (x, y) => {
                loadingSpinner.gameObject.SetActive(true);
                SceneNavigator.Instance.OnSceneDidTransitionOut -= onDidOut;
            };
            SceneNavigator.Instance.OnSceneDidTransitionOut += onDidOut;

            System.Action <SceneController, SceneTransition> onWillIn = null;
            onWillIn = (x, y) => {
                if (loadingSpinner && allowShutdown)
                {
                    Destroy(loadingSpinner.gameObject);
                    SceneNavigator.Instance.OnSceneWillTransitionIn -= onWillIn;
                }
            };
            SceneNavigator.Instance.OnSceneWillTransitionIn += onWillIn;

            System.Action <SceneController, SceneTransition> onDidIn = null;
            onDidIn = (x, y) => {
                allowShutdown = true;
                SceneNavigator.Instance.OnSceneDidTransitionIn -= onDidIn;
            };
            SceneNavigator.Instance.OnSceneDidTransitionIn += onDidIn;

            return(loadingSpinner);
        }