Exemple #1
0
 public void NavigateToProject()
 {
     if (this.IsReady && (this.State == ProjectNavigatorState.Content || this.State == ProjectNavigatorState.Error))
     {
         this.ProgressReport.Reset();
         this.State = ProjectNavigatorState.NavigateToProject;
         this.CoroutineHelper.StartCoroutine("NavigateToProject", NavigateToProjectImpl());
     }
     else
     {
         throw new System.InvalidOperationException("Cannot navigate to project.");
     }
 }
Exemple #2
0
 public void NavigateToContent(ContentInfo contentInfo)
 {
     if (this.IsReady && this.State == ProjectNavigatorState.Project)
     {
         this.ContentInfo = contentInfo;
         this.ProgressReport.Reset();
         this.State = ProjectNavigatorState.NavigateToContent;
         this.CoroutineHelper.StartCoroutine("NavigateToContent", NavigateToContentImpl());
     }
     else
     {
         throw new System.InvalidOperationException("Cannot navigate to content.");
     }
 }
Exemple #3
0
        /// <summary>
        /// Coroutine implementation for navigating to error scene.
        /// </summary>
        /// <returns>IEnumerator</returns>
        /// <param name="errorType">This is meant for errors that we know of and defined in some form of data like enum types.</param>
        /// <param name="errorMessage">This is a raw string in the case of any errors that we do not know of.</param>
        private IEnumerator NavigateToErrorImpl(ProjectNavigatorError errorType, string errorMessage)
        {
            // Shouldn't call deactivate content here since error is being treated as a medium that
            // sits between project navigation and content navigation, and project navigation logic takes
            // care of this aspect; so if we try to call deactivate content here then any navigation logic
            // that uses content info (in this case, navigating to project) will make the app to crash.

            if (WillNavigateToError != null)
            {
                WillNavigateToError(this.ContentInfo, errorType.ToString(), errorMessage);
            }

            // After we've handled unloading unnecessary resources, we can now navigate to error scene
            SceneNavigator.Instance.NavigateToScene(
                ProjectInfo.Instance.NavigateToErrorScene,
                Instantiate(ProjectInfo.Instance.NavigateToErrorTransition),
                Instantiate(ProjectInfo.Instance.NavigateToErrorTransition),
                null,
                true,
                true
                );

            while (!SceneNavigator.Instance.IsReady)
            {
                yield return(null);
            }

            // apply auto rotation and orientation
            ApplyScreenAutoRotationAndOrientation();

            this.State = ProjectNavigatorState.Error;

            if (DidNavigateToError != null)
            {
                DidNavigateToError(this.ContentInfo, errorType.ToString(), errorMessage);
            }
        }
Exemple #4
0
        private IEnumerator NavigateToContentImpl()
        {
            if (SceneNavigator.Instance)
            {
                if (WillNavigateToContent != null)
                {
                    WillNavigateToContent(this.ContentInfo);
                }

                CreateLoadingSpinner(
                    ProjectInfo.Instance.NavigateToContentLoadingSpinner,
                    () => {
                    return((int)(this.ProgressReport != null ? this.ProgressReport.TotalProgress * 100f : 0));
                });

                // go to the navigate to content scene
                SceneNavigator.Instance.NavigateToScene(
                    ProjectInfo.Instance.NavigateToContentScene,
                    Instantiate(ProjectInfo.Instance.NavigateToContentTransition),
                    Instantiate(ProjectInfo.Instance.NavigateToContentTransition),
                    null,
                    true,
                    true
                    );
                while (SceneNavigator.Instance.IsBusy)
                {
                    yield return(null);
                }

                // unload the home scene
                yield return(Resources.UnloadUnusedAssets());

                // save auto rotation and orientation settings
                SaveScreenAutoRotationAndOrientation();

                // event
                this.ContentInfo.OnProjectNavigatorWillActivateContent();

                // apply the content settings
                ApplyContentSettings(this.ContentInfo);

                                #if !UNITY_EDITOR
                AssetBundleAdaptorType resourceContentAssetBundleAdaptorType = AssetBundleAdaptorMap.Instance.GetAdaptorType(this.ContentInfo.ResourceAssetBundleName);
                AssetBundleAdaptorType sceneContentAssetBundleAdaptorType    = AssetBundleAdaptorMap.Instance.GetAdaptorType(this.ContentInfo.SceneAssetBundleName);

                if ((resourceContentAssetBundleAdaptorType == AssetBundleAdaptorType.OnDemandResources || resourceContentAssetBundleAdaptorType == AssetBundleAdaptorType.AssetBundleServer) ||
                    (sceneContentAssetBundleAdaptorType == AssetBundleAdaptorType.OnDemandResources || sceneContentAssetBundleAdaptorType == AssetBundleAdaptorType.AssetBundleServer))
                {
                    // Query to see if resources that we need to load are already downloaded and available
                    using (var resourceQueryYieldInstruction = new ResourceQueryYieldInstruction(this, this.ContentInfo.ResourceAssetBundleName, this.ContentInfo.SceneAssetBundleName))
                    {
                        Debug.Log("ProjectNavigator-> Querying For Content Resource Availability.", DebugContext.SagoApp);
                        yield return(resourceQueryYieldInstruction);

                        // If resource and scene are not already downloaded and available we need to test internet reachability before before start downloading.
                        if (!resourceQueryYieldInstruction.IsResourceAvailable)
                        {
                            // Testing internet reachability and stop loading ODR if there is any error.
                            using (InternetReachabilityYieldInstruction reachabilityYieldInstruction = new InternetReachabilityYieldInstruction(this))
                            {
                                yield return(reachabilityYieldInstruction);

                                if (!reachabilityYieldInstruction.IsInternetReachable)
                                {
                                    this.Error = reachabilityYieldInstruction.Error;
                                    NavigateToError(this.Error, "Internet is not reachable.");
                                    // Since internet is not reachable we need to stop all remaining processes.
                                    yield break;
                                }
                            }
                        }
                    }
                }
                                #endif

                if (NavigateToContentWillLoadAssetBundles != null)
                {
                    NavigateToContentWillLoadAssetBundles(this.ContentInfo);
                }

                // load the content asset bundles
                if (AssetBundleOptions.UseAssetBundlesInEditor)
                {
                    Debug.LogFormat(DebugContext.SagoApp, "ProjectNavigator-> Finding or creating reference to asset bundle: {0}", this.ContentInfo.ResourceAssetBundleName);
                    this.ResourceAssetBundle = AssetBundleReference.FindOrCreateReference(this.ContentInfo.ResourceAssetBundleName);
                    this.ResourceAssetBundle.Retain();

                    this.ProgressReport.Index = 0;
                    this.ProgressReport.Count = 3;
                    this.ProgressReport.Item  = new LoadAssetBundleProgressReportItem(this.ResourceAssetBundle);
                    yield return(this.ResourceAssetBundle);

                    Debug.LogFormat(DebugContext.SagoApp, "ProjectNavigator-> Completed finding or creating reference to asset bundle: {0}", this.ContentInfo.ResourceAssetBundleName);
                    if (!string.IsNullOrEmpty(this.ResourceAssetBundle.error))
                    {
                        Debug.LogError(this.ResourceAssetBundle.error, DebugContext.SagoApp);
                        if (string.Equals(this.ResourceAssetBundle.error, LowDiskSpaceAssetBundleAdaptor.LowDiskSpaceError))
                        {
                            this.Error = ProjectNavigatorError.LowDiskSpace;
                        }
                        else if (string.Equals(this.ResourceAssetBundle.error, AssetBundleAdaptorError.NoInternet))
                        {
                            this.Error = ProjectNavigatorError.OdrErrorNoInternet;
                        }
                        else
                        {
                            this.Error = ProjectNavigatorError.OdrErrorUnknown;
                        }
                        if (NavigateToContentDidLoadAssetBundles != null)
                        {
                            NavigateToContentDidLoadAssetBundles(this.ContentInfo, false);
                        }
                        NavigateToError(this.Error, this.ResourceAssetBundle.error);
                        yield break;
                    }

                    Debug.LogFormat(DebugContext.SagoApp, "ProjectNavigator-> Finding or creating reference to asset bundle: {0}", this.ContentInfo.SceneAssetBundleName);
                    this.SceneAssetBundle = AssetBundleReference.FindOrCreateReference(this.ContentInfo.SceneAssetBundleName);
                    this.SceneAssetBundle.Retain();

                    this.ProgressReport.Index = 1;
                    this.ProgressReport.Item  = new LoadAssetBundleProgressReportItem(this.SceneAssetBundle);
                    yield return(this.SceneAssetBundle);

                    Debug.LogFormat(DebugContext.SagoApp, "ProjectNavigator-> Completed finding or creating reference to asset bundle: {0}", this.ContentInfo.SceneAssetBundleName);
                    if (!string.IsNullOrEmpty(this.SceneAssetBundle.error))
                    {
                        Debug.LogError(this.SceneAssetBundle.error, DebugContext.SagoApp);
                        if (string.Equals(this.SceneAssetBundle.error, LowDiskSpaceAssetBundleAdaptor.LowDiskSpaceError))
                        {
                            this.Error = ProjectNavigatorError.LowDiskSpace;
                        }
                        else if (string.Equals(this.SceneAssetBundle.error, AssetBundleAdaptorError.NoInternet))
                        {
                            this.Error = ProjectNavigatorError.OdrErrorNoInternet;
                        }
                        else
                        {
                            this.Error = ProjectNavigatorError.OdrErrorUnknown;
                        }
                        if (NavigateToContentDidLoadAssetBundles != null)
                        {
                            NavigateToContentDidLoadAssetBundles(this.ContentInfo, false);
                        }
                        NavigateToError(this.Error, this.SceneAssetBundle.error);
                        yield break;
                    }
                }

                if (NavigateToContentDidLoadAssetBundles != null)
                {
                    NavigateToContentDidLoadAssetBundles(this.ContentInfo, true);
                }

                // event
                this.ContentInfo.OnProjectNavigatorDidActivateContent();

                if (NavigateToContentWillLoadMainScene != null)
                {
                    NavigateToContentWillLoadMainScene(this.ContentInfo);
                }

                // load the initial scene
                SceneNavigator.Instance.LoadScene(this.ContentInfo.MainScene);
                this.ProgressReport.Index = 2;
                this.ProgressReport.Item  = new LoadSceneProgressReportItem(this.ContentInfo.MainScene);
                while (!SceneNavigator.Instance.SceneIsLoaded(this.ContentInfo.MainScene))
                {
                    yield return(null);
                }

                if (NavigateToContentDidLoadMainScene != null)
                {
                    NavigateToContentDidLoadMainScene(this.ContentInfo, true);
                }

                // go to the initial scene
                SceneNavigator.Instance.NavigateToScene(
                    this.ContentInfo.MainScene,
                    Instantiate(ProjectInfo.Instance.NavigateToContentTransition),
                    Instantiate(ProjectInfo.Instance.NavigateToContentTransition),
                    null,
                    true,
                    true
                    );
                while (!SceneNavigator.Instance.IsReady)
                {
                    yield return(null);
                }

                this.ProgressReport.Reset();

                // set state
                this.State = ProjectNavigatorState.Content;

                if (DidNavigateToContent != null)
                {
                    DidNavigateToContent(this.ContentInfo);
                }
            }
        }
Exemple #5
0
        private IEnumerator NavigateToProjectImpl()
        {
            if (SceneNavigator.Instance)
            {
                // store content info in a local variable so that it can be used after the ContentInfo property is cleared
                ContentInfo contentInfo;
                contentInfo = this.ContentInfo;

                if (WillNavigateToProject != null)
                {
                    WillNavigateToProject(contentInfo);
                }

                CreateLoadingSpinner();

                // go to the navigate to project scene
                SceneNavigator.Instance.NavigateToScene(
                    ProjectInfo.Instance.NavigateToProjectScene,
                    Instantiate(ProjectInfo.Instance.NavigateToProjectTransition),
                    Instantiate(ProjectInfo.Instance.NavigateToProjectTransition),
                    null,
                    true,
                    true
                    );
                while (!SceneNavigator.Instance.IsReady)
                {
                    yield return(null);
                }

                yield return(StartCoroutine(DeactivateContent(contentInfo)));

                yield return(StartCoroutine(UnloadContentScenes(contentInfo)));

                // clear auto rotation and orientation
                ClearScreenAutoRotationAndOrientation();

                // load the home scene
                SceneNavigator.Instance.LoadScene(ProjectInfo.Instance.MainScene);
                while (!SceneNavigator.Instance.SceneIsLoaded(ProjectInfo.Instance.MainScene))
                {
                    yield return(null);
                }

                // go to the home scene
                SceneNavigator.Instance.NavigateToScene(
                    ProjectInfo.Instance.MainScene,
                    Instantiate(ProjectInfo.Instance.NavigateToProjectTransition),
                    Instantiate(ProjectInfo.Instance.NavigateToProjectTransition),
                    null,
                    true,
                    true
                    );
                while (!SceneNavigator.Instance.IsReady)
                {
                    yield return(null);
                }

                // set state
                this.State = ProjectNavigatorState.Project;

                if (DidNavigateToProject != null)
                {
                    DidNavigateToProject(contentInfo);
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// Call to navigate to error scene.
 /// </summary>
 /// <param name="errorType">This is meant for errors that we know of and defined in some form of data like enum types.</param>
 /// <param name="errorMessage">This is a raw string in the case of any errors that we do not know of.</param>
 public void NavigateToError(ProjectNavigatorError errorType, string errorMessage)
 {
     this.State = ProjectNavigatorState.NavigateToError;
     this.CoroutineHelper.StartCoroutine("NavigateToError", NavigateToErrorImpl(errorType, errorMessage));
 }