Beispiel #1
0
        public static bool IsLocal(this AssetBundleAdaptorType adaptorType)
        {
            switch (adaptorType)
            {
            case AssetBundleAdaptorType.StreamingAssets:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #2
0
        public static bool IsRemote(this AssetBundleAdaptorType adaptorType)
        {
            switch (adaptorType)
            {
            case AssetBundleAdaptorType.AssetBundleServer:
            case AssetBundleAdaptorType.OnDemandResources:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Sets the remote adaptor type.
 /// </summary>
 /// <param name="adaptorType">
 /// The adaptor type.
 /// </param>
 /// <remarks>
 /// <para>
 /// The remote adaptor type must be set before bootstrapping the <see cref="AssetBundleAdaptorMap" />
 /// (so the <see cref="AssetBundleDeploymentType" /> in the <see cref="AssetBundleMap" /> can be
 /// resolved to an <see cref="AssetBundleAdaptorType" /> in the <see cref="AssetBundleAdaptorMap" />).
 /// </para>
 /// <para>
 /// In Cloud Build, the remote adaptor type will need to be set using one of the following define symbols:
 /// <code>
 /// SAGO_ASSET_BUNDLES_USE_ON_DEMAND_RESOURCES
 /// SAGO_ASSET_BUNDLES_USE_DEVELOPMENT_SERVER
 /// SAGO_ASSET_BUNDLES_USE_STAGING_SERVER
 /// SAGO_ASSET_BUNDLES_USE_PRODUCTION_SERVER
 /// </code>
 /// </para>
 /// <para>
 /// In the editor, the remote adaptor type will need be set by the method that
 /// starts a build. We don't want to use define symbols in the editor because
 /// the remote adaptor type is build-specific and shouldn't be committed to the
 /// repository (define symbols are stored in Unity's project settings which are
 /// committed to the repository).
 /// </para>
 /// </remarks>
 public static void SetRemoteAdaptorType(AssetBundleAdaptorType adaptorType)
 {
                 #if !(UNITY_CLOUD_BUILD || TEAMCITY_BUILD)
     if (adaptorType == AssetBundleAdaptorType.Unknown)
     {
         EditorPrefs.DeleteKey(RemoteAdaptorTypeKey);
     }
     else
     {
         EditorPrefs.SetInt(RemoteAdaptorTypeKey, (int)adaptorType);
     }
                 #endif
 }
Beispiel #4
0
        private IEnumerator RefreshDownload(string resourceAssetBundleName, string sceneAssetBundleName)
        {
                        #if !UNITY_EDITOR
            AssetBundleAdaptorType resourceContentAssetBundleAdaptorType = AssetBundleAdaptorMap.Instance.GetAdaptorType(resourceAssetBundleName);
            AssetBundleAdaptorType sceneContentAssetBundleAdaptorType    = AssetBundleAdaptorMap.Instance.GetAdaptorType(sceneAssetBundleName);

            if (resourceContentAssetBundleAdaptorType.IsRemote() || sceneContentAssetBundleAdaptorType.IsRemote())
            {
                // Query to see if resources that we need to load are already downloaded and available
                using (var resourceQueryYieldInstruction = new ResourceQueryYieldInstruction(m_MonoBehaviour, resourceAssetBundleName, sceneAssetBundleName)) {
                    Debug.Log("ContentDownloader-> Querying For Content Resource Availability.", DebugContext.SagoApp);
                    yield return(resourceQueryYieldInstruction);

                    // Update state if the resource is already downloaded or not
                    if (resourceQueryYieldInstruction.IsResourceAvailable)
                    {
                        m_DownloadState = ContentDownloadState.Complete;
                    }
                    else
                    {
                        m_DownloadState = ContentDownloadState.Unknown;
                    }
                }
                Complete();
                yield break;
            }
            else
            {
                m_DownloadState = ContentDownloadState.Complete;
                Complete();
                yield break;
            }
                        #else
            m_DownloadState = ContentDownloadState.Complete;
            Complete();
            yield break;
                        #endif
        }
Beispiel #5
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);
                }
            }
        }