public static void ResourceQueryCallback(int queryId, bool available)
        {
            // What's the probability of query object's hashcode collision?
            ResourceQueryYieldInstruction query = m_ResourceQueryContainer[queryId];

            if (query != null)
            {
                query.OnResourceQueryComplete(available);
            }
            m_ResourceQueryContainer.Remove(queryId);
        }
Beispiel #2
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);
                }
            }
        }