public IEnumerator LoadSceneAsync(string scenePath, LoadSceneMode mode = LoadSceneMode.Single)
        {
#if UNITY_EDITOR
            if (AssetBundleUtility.SimulateAssetBundleInEditor)
            {
                string path = Path.Combine(AssetBundleUtility.AssetBundleResourcesPath, scenePath) + ".unity";
                if (mode == LoadSceneMode.Single)
                {
                    yield return(EditorApplication.LoadLevelAsyncInPlayMode(path));
                }
                else
                {
                    yield return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(path));
                }
                yield break;
            }
#endif

            yield return(StartCoroutine(LoadAssetBundleWithDependenciesAsync(scenePath + AssetBundleUtility.AssetBundleExtension)));

            LoadSceneAsyncOpe = SceneManager.LoadSceneAsync(Path.GetFileName(scenePath), mode);
            yield return(LoadSceneAsyncOpe);

            LoadSceneAsyncOpe = null;
        }
Exemple #2
0
    public static AsyncOperation LoadSceneOnEditor(string guid, bool bAsync, bool bAdditive)
    {
        string scenePath = AssetDatabase.GUIDToAssetPath(guid);

        if (bAsync)
        {
            if (bAdditive)
            {
                return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenePath));
            }
            else
            {
                return(EditorApplication.LoadLevelAsyncInPlayMode(scenePath));
            }
        }
        else
        {
            if (bAdditive)
            {
                EditorApplication.LoadLevelAdditiveInPlayMode(scenePath);
            }
            else
            {
                EditorApplication.LoadLevelInPlayMode(scenePath);
            }

            return(null);
        }
    }
Exemple #3
0
        private void AsyncLoadScene(SceneLoadItem load_item)
        {
#if UNITY_EDITOR
            string[] paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(
                load_item.asset_id.bundleName,
                load_item.asset_id.assetName);

            if (paths.Length <= 0)
            {
                return;
            }

            AsyncOperation asyncOperation;
            if (LoadSceneMode.Additive == load_item.load_mode)
            {
                asyncOperation = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(paths[0]);
            }
            else
            {
                asyncOperation = EditorApplication.LoadLevelAsyncInPlayMode(paths[0]);
            }

            WaitLoadSceneItem wait_item = new WaitLoadSceneItem();
            wait_item.load_item      = load_item;
            wait_item.asyncOperation = asyncOperation;
            this.wait_list.Add(wait_item);
#endif
        }
        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);
        }
Exemple #5
0
 protected override AsyncOperation LoadScene(string path, bool additive)
 {
     if (additive)
     {
         return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(path));
     }
     return(EditorApplication.LoadLevelAsyncInPlayMode(path));
 }
 public AsyncOperation LoadSceneAsync(string assetbundlename, string scenename, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
 {
     if (loadSceneMode == LoadSceneMode.Additive)
     {
         return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenename));
     }
     else
     {
         return(EditorApplication.LoadLevelAsyncInPlayMode(scenename));
     }
 }
 /// <summary>
 /// 异步加载场景
 /// </summary>
 /// <param name="sceneName"></param>
 public AsyncOperation LoadSceneAsync(string assetBundleName, string sceneName, LoadSceneMode mode = LoadSceneMode.Additive)
 {
     if (mode == LoadSceneMode.Additive)
     {
         return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(sceneName));
     }
     else
     {
         return(EditorApplication.LoadLevelAsyncInPlayMode(sceneName));
     }
     //  return UnitySceneManager.LoadSceneAsync(sceneName, mode);
 }
        public SceneLoadOperation(string bundleName, string sceneName, bool isAdditive)
        {
            m_AssetBundleName = bundleName;
            m_SceneName       = sceneName;
            m_IsAdditive      = isAdditive;
            id = GetId(m_AssetBundleName, m_SceneName);

            AssetManager.AddDepend(m_AssetBundleName, id);

#if UNITY_EDITOR
            // シミュレーションモード中. アセットバンドルはAssetDatabaseを利用してロード.
            // Simulation mode (only in editor).
            if (AssetManager.isSimulationMode)
            {
                var filter = string.IsNullOrEmpty(bundleName) ? "t:Scene" : "t:Scene b:" + bundleName;
                var path   = AssetDatabase.FindAssets(filter + " " + sceneName)
                             .Select(AssetDatabase.GUIDToAssetPath)
                             .FirstOrDefault(x => Path.GetFileNameWithoutExtension(x) == sceneName);

                if (!string.IsNullOrEmpty(path))
                {
                    m_Request = isAdditive
                                                ? EditorApplication.LoadLevelAsyncInPlayMode(path)
                                                : EditorApplication.LoadLevelAdditiveAsyncInPlayMode(path);
                }
                else
                {
                    if (string.IsNullOrEmpty(m_AssetBundleName))
                    {
                        error = string.Format("シーン {0} が見つかりませんでした(シミュレーションモード)", m_SceneName);
                    }
                    else
                    {
                        error = string.Format("アセットバンドル {0} 内に、シーン {1} が見つかりませんでした(シミュレーションモード)", m_AssetBundleName, m_SceneName);
                    }
                }

                progress = 1f;
                return;
            }
#endif

            // アセットバンドルではない.
            if (string.IsNullOrEmpty(m_AssetBundleName))
            {
                m_Request = SceneManager.LoadSceneAsync(sceneName, isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);
            }
        }
Exemple #9
0
        public IObservable <AsyncOperation> LoadScene(Scene scene, bool isAdditive)
        {
            string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(scene.assetBundleName, scene.sceneName);
            if (levelPaths.Length == 0)
            {
                Assert.IsTrue(false, "There is no scene " + scene.sceneName + " in asset bundle " + scene.assetBundleName);
                return(Observable.Throw <AsyncOperation>(new AssetBundleException("Could not load scene " + scene.sceneName)));
            }

            if (isAdditive)
            {
                return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]).AsAsyncOperationObservable());
            }
            else
            {
                return(EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]).AsAsyncOperationObservable());
            }
        }
Exemple #10
0
        public AssetBundleSceneSimulationOperation(string _assetBundleName, string _sceneName, bool _isAdditive)
        {
#if UNITY_EDITOR
            string[] scenePaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(_assetBundleName, _sceneName);
            if (scenePaths.Length == 0)
            {
                Debug.LogError(string.Format("没有这个名字的场景: {0}, 在assetbundle:{1}", _sceneName, _assetBundleName));
                return;
            }
            if (_isAdditive)
            {
                mOperation = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenePaths[0]);
            }
            else
            {
                mOperation = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenePaths[0]);
            }
#endif
        }
    public AssetBundleLoadLevelSimulationOperation(string assetBundleName, string levelName, bool isAdditive)//
    {
        string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName);
        if (levelPaths.Length == 0)
        {
            ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist
            //        from that there right scene does not exist in the asset bundle...

            Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName);
            return;
        }

        if (isAdditive)
        {
            m_Operation = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]);
        }
        else
        {
            m_Operation = EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]);
        }
    }
Exemple #12
0
    // Load level from the given assetBundle.
    static public AssetBundleLoadBaseOperation LoadLevelAsync(string assetBundleName, string levelName, bool isAdditive)
    {
        AssetBundleLoadBaseOperation operation = null;
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName);
            if (levelPaths.Length == 0)
            {
                ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist
                //        from that there right scene does not exist in the asset bundle...

                SampleDebuger.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName);
                return null;
            }

            AssetBundleLoadLevelSimulationOperation temp = new AssetBundleLoadLevelSimulationOperation();
            if (isAdditive)
                temp.m_sceneRequest = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]);
            else
                temp.m_sceneRequest = EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]);

            operation = temp;

        }
        else
#endif
        {
            LoadAssetBundle(assetBundleName);
            operation = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive);

            m_InProgressOperations.Add(operation);
        }

        return operation;
    }
Exemple #13
0
    public override bool Update()
    {
#if UNITY_EDITOR
        if (AssetBundleLoadManager.SimulateAssetBundleInEditor)
        {
            string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_AssetBundleName, m_AssetName);
            if (levelPaths.Length == 0)
            {
                ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist
                //        from that there right scene does not exist in the asset bundle...

                Debug.LogError("There is no scene with name \"" + m_AssetName + "\" in " + m_AssetBundleName);
                return(true);
            }


            if (m_IsAdditive)
            {
                m_Request = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]);
            }
            else
            {
                m_Request = EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]);
            }

            m_IsDone = true;
            DoCallback();
            return(false);
        }
#endif



        if (m_Request != null && m_Request.isDone)
        {
            m_IsDone = true;
            DoCallback();
            return(false);
        }
        else if (m_Request != null && !m_Request.isDone)
        {
            return(true);
        }

        LoadedAssetBundle bundle = AssetBundleLoadManager.Instance.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);
        if (bundle != null)
        {
            if (m_IsAdditive)
            {
                m_Request = Application.LoadLevelAdditiveAsync(m_AssetName);
            }
            else
            {
                m_Request = Application.LoadLevelAsync(m_AssetName);
            }
            return(true);
        }
        else
        {
            return(true);
        }
    }