protected override IEnumerator DoLoadSceneAsync(ISceneLoadingPromise <Scene> promise, string path, LoadSceneMode mode = LoadSceneMode.Single)
        {
            AssetPathInfo pathInfo = pathInfoParser.Parse(path);

            if (pathInfo == null)
            {
                promise.Progress = 0f;
                promise.SetException(string.Format("Parses the path info '{0}' failure.", path));
                yield break;
            }

            var name = string.Format("{0}{1}", ASSETS, pathInfo.AssetName);

#if UNITY_2018_3_OR_NEWER
            AsyncOperation operation = EditorSceneManager.LoadSceneAsyncInPlayMode(name, new LoadSceneParameters(mode));
#else
            AsyncOperation operation = LoadSceneMode.Additive.Equals(mode) ? EditorApplication.LoadLevelAdditiveAsyncInPlayMode(name) : EditorApplication.LoadLevelAsyncInPlayMode(name);
#endif
            if (operation == null)
            {
                promise.SetException(string.Format("Not found the scene '{0}'.", path));
                yield break;
            }

            operation.allowSceneActivation = false;
            while (operation.progress < 0.9f)
            {
                if (operation.progress == 0f)
                {
                    operation.priority = promise.Priority;
                }

                promise.Progress = operation.progress;
                yield return(waitForSeconds);
            }
            promise.Progress = operation.progress;
            promise.State    = LoadState.SceneActivationReady;

            while (!operation.isDone)
            {
                if (promise.AllowSceneActivation && !operation.allowSceneActivation)
                {
                    operation.allowSceneActivation = promise.AllowSceneActivation;
                }

                promise.Progress = operation.progress;
                yield return(waitForSeconds);
            }

            Scene scene = SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(pathInfo.AssetName));
            if (!scene.IsValid())
            {
                promise.SetException(string.Format("Not found the scene '{0}'.", path));
                yield break;
            }

            promise.Progress = 1f;
            promise.SetResult(scene);
        }
Beispiel #2
0
        protected override IEnumerator DoLoadSceneAsync(ISceneLoadingPromise <Scene> promise, string path, LoadSceneMode mode = LoadSceneMode.Single)
        {
            AssetPathInfo pathInfo = pathInfoParser.Parse(path);

            if (pathInfo == null)
            {
                promise.Progress = 0f;
                promise.SetException(string.Format("Parses the path info '{0}' failure.", path));
                yield break;
            }

            AsyncOperation operation = SceneManager.LoadSceneAsync(Path.GetFileNameWithoutExtension(pathInfo.AssetName), mode);

            if (operation == null)
            {
                promise.SetException(string.Format("Not found the scene '{0}'.", path));
                yield break;
            }

            operation.allowSceneActivation = false;
            while (operation.progress < 0.9f)
            {
                if (operation.progress == 0f)
                {
                    operation.priority = promise.Priority;
                }

                promise.Progress = operation.progress;
                yield return(waitForSeconds);
            }
            promise.Progress = operation.progress;
            promise.State    = LoadState.SceneActivationReady;

            while (!operation.isDone)
            {
                if (promise.AllowSceneActivation && !operation.allowSceneActivation)
                {
                    operation.allowSceneActivation = promise.AllowSceneActivation;
                }

                promise.Progress = operation.progress;
                yield return(waitForSeconds);
            }

            Scene scene = SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(pathInfo.AssetName));

            if (!scene.IsValid())
            {
                promise.SetException(string.Format("Not found the scene '{0}'.", path));
                yield break;
            }

            promise.Progress = 1f;
            promise.SetResult(scene);
        }
Beispiel #3
0
        protected override IEnumerator DoLoadSceneAsync(ISceneLoadingPromise <Scene> promise, string path, LoadSceneMode mode = LoadSceneMode.Single)
        {
            AssetPathInfo pathInfo = pathInfoParser.Parse(path);

            if (pathInfo == null)
            {
                promise.Progress = 1f;
                promise.SetException(string.Format("Parses the path info '{0}' failure.", path));
                yield break;
            }

            yield return(null);//Wait for a frame.

            IProgressResult <float, IBundle> bundleResult = this.LoadBundle(pathInfo.BundleName, promise.Priority);
            float weight = bundleResult.IsDone ? 0f : DEFAULT_WEIGHT;

            bundleResult.Callbackable().OnProgressCallback(p => promise.Progress = p * weight);

            while (!bundleResult.IsDone)
            {
                yield return(null);
            }

            if (bundleResult.Exception != null)
            {
                promise.SetException(bundleResult.Exception);
                yield break;
            }

            promise.State = LoadState.AssetBundleLoaded;

            using (IBundle bundle = bundleResult.Result)
            {
                AsyncOperation operation = SceneManager.LoadSceneAsync(Path.GetFileNameWithoutExtension(pathInfo.AssetName), mode);
                if (operation == null)
                {
                    promise.SetException(string.Format("Not found the scene '{0}'.", path));
                    yield break;
                }
                operation.priority             = promise.Priority;
                operation.allowSceneActivation = false;
                while (operation.progress < 0.9f)
                {
                    promise.Progress = weight + (1f - weight) * operation.progress;
                    yield return(waitForSeconds);
                }
                promise.Progress = weight + (1f - weight) * operation.progress;
                promise.State    = LoadState.SceneActivationReady;
                while (!operation.isDone)
                {
                    if (promise.AllowSceneActivation && !operation.allowSceneActivation)
                    {
                        operation.allowSceneActivation = promise.AllowSceneActivation;
                    }

                    promise.Progress = weight + (1f - weight) * operation.progress;
                    yield return(waitForSeconds);
                }

                Scene scene = SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(pathInfo.AssetName));
                if (!scene.IsValid())
                {
                    promise.SetException(string.Format("Not found the scene '{0}'.", path));
                    yield break;
                }

                promise.Progress = 1f;
                promise.SetResult(scene);
            }
        }