Exemple #1
0
 public AssetBundleLoadLevelOperation(string assetbundleName, string levelName, bool isAdditive, LoadSceneCallback callback, object[] param)
 {
     m_AssetBundleName = assetbundleName;
     m_LevelName       = levelName;
     m_IsAdditive      = isAdditive;
     this.callback     = callback;
     this.param        = param;
 }
Exemple #2
0
        private IEnumerator LoadBundleScene(string path, LoadSceneCallback callback)
        {
            var request = new WWW(path.StartsWith("jar:")?path:"file:///" + path);

            while (!request.isDone)
            {
                if (string.IsNullOrEmpty(request.error))
                {
                    yield return(request);
                }
                else
                {
                    break;
                }
            }

            if (string.IsNullOrEmpty(request.error))
            {
                var bundle    = request.assetBundle;
                var sceneName = bundle.GetAllScenePaths()[0];
                var op        = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName);

                yield return(op);

                //while (!op.isDone) {
                //	yield return new WaitForEndOfFrame();
                //}

                Debug.LogError("loaded " + sceneName);

                if (callback != null)
                {
                    callback(0, sceneName);
                }

                bundle.Unload(true);
            }
            else
            {
                if (callback != null)
                {
                    Debug.LogErrorFormat("LoadBundleScene {0} error with {1}", path, request.error);
                    callback(-1, path);
                }
            }

            request.Dispose();
            request = null;
        }
Exemple #3
0
        private IEnumerator LoadBundleScene(AssetBundle bundle, LoadSceneCallback callback)
        {
            var sceneName = bundle.GetAllScenePaths()[0];

            var op = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName);

            LoadResult loaded = new LoadResult(op.isDone);

            UnityAction <UnityEngine.SceneManagement.Scene, UnityEngine.SceneManagement.LoadSceneMode> func = delegate(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.LoadSceneMode arg1) {
                if (arg0.name.ToLower().Equals(bundle.name))
                {
                    loaded.value = true;
                }

                print(arg0.name.ToLower() + "," + bundle.name + "," + loaded + "," + op.isDone);
            };

            UnityEngine.SceneManagement.SceneManager.sceneLoaded += func;

            while (!loaded.value)
            {
                Debug.LogError("loaded" + loaded.value);
                yield return(new WaitForEndOfFrame());
            }

            UnityEngine.SceneManagement.SceneManager.sceneLoaded -= func;

            Debug.LogError("loaded " + sceneName);

            if (callback != null)
            {
                callback(0, sceneName);
            }

            bundle.Unload(true);
        }
Exemple #4
0
 public virtual void LoadSceneByName(string name, LoadSceneCallback callback)
 {
     StartCoroutine(LoadBundleScene(name, callback));
 }
Exemple #5
0
 public virtual void LoadScene(AssetBundle bundle, LoadSceneCallback callback)
 {
     StartCoroutine(LoadBundleScene(bundle, callback));
 }
Exemple #6
0
        public void LoadScene(string assetBundleName, string levelName, bool isAdditive, LoadSceneCallback callback, object[] param)
        {
            AssetBundleLoadLevelOperation operation = null;

#if UNITY_EDITOR
            if (AssetLoader2.m_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...

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

                if (isAdditive)
                {
                    EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
                }
                else
                {
                    EditorApplication.LoadLevelInPlayMode(levelPaths[0]);
                }
            }
            else
#endif
            {
                LoadAssetBundle(assetBundleName);
                operation          = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive, callback, param);
                operation.callback = callback;
                operation.loader   = this;
                m_InProgressOperations.Add(operation);
            }
        }
Exemple #7
0
 public void LoadScene(string assetBundleName, string levelName, bool isAdditive, LoadSceneCallback callback, params object[] param)
 {
     LoggerHelper.Debug("begin to load scene assetBundleName:" + assetBundleName + ",level:" + levelName);
     resLoader.LoadScene(assetBundleName, levelName, isAdditive, callback, param);
 }
Exemple #8
0
 public static void SwitchSceneAsych(string sceneName, LoadSceneCallback callback)
 {
     capsule.model.GetComponent <Model>().SceneLoadAsynch(sceneName, callback);
 }