Beispiel #1
0
    protected IEnumerator InitializeLevelAsync(string levelName, bool isAdditive)
    {
        // This is simply to get the elapsed time for this phase of AssetLoading.
        float startTime = Time.realtimeSinceStartup;

        // Load level from assetBundle.
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);

        if (request == null)
        {
            yield break;
        }

        yield return(StartCoroutine(request));

        // Trigger callbacks once the scene has loaded
        //OnFinished(true);
        finishedLoading = true;

        if (NetworkManager.singleton.isNetworkActive && NetworkServer.connections.Count > 0)
        {
            NetworkServer.SpawnObjects();
        }

        // Calculate and display the elapsed time.
        float elapsedTime = Time.realtimeSinceStartup - startTime;

        Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
    }
	// Load level from the given assetBundle.
	static public AssetBundleLoadOperation LoadLevelAsync (string assetBundleName, string levelName, bool isAdditive)
	{
		AssetBundleLoadOperation 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...
			
				Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName);
				return null;
			}

			if (isAdditive)
				EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
			else
				EditorApplication.LoadLevelInPlayMode(levelPaths[0]);

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

			m_InProgressOperations.Add (operation);
		}

		return operation;
	}
        IEnumerator <YieldInstruction> InitializeAndThenLoadSceneIntoLevel(string assetBundleName, string sceneName)
        {
#if DLK_AssetBundleIntegrationEnabled
            initialized = true;

            if (variantPossibilities != null && variantPossibilities.Length > 0)
            {
                SetVariant(activeVariant);
            }
            else
            {
                variantPossibilities = null;
                activeVariant        = null;
            }

            AssetBundleManager.logMode = logMode == AssetBundleManagerLogMode.All ? AssetBundleManager.LogMode.All : AssetBundleManager.LogMode.JustErrors;

            if (streamingType == StreamingType.SimulationModeOrLocalAssetServer)
            {
                AssetBundleManager.SetDevelopmentAssetBundleServer();
            }
            else if (streamingType == StreamingType.StreamingAssetsFolder)
            {
                AssetBundleManager.SetSourceAssetBundleURL("file:///" + Application.streamingAssetsPath + "/");
            }
            else
            {
                AssetBundleManager.SetSourceAssetBundleURL(serverURL);
            }

            // Initialize AssetBundleManifest which loads the AssetBundleManifest object.
            var initializeRequest = AssetBundleManager.Initialize();

            if (initializeRequest != null)
            {
                while (initializeRequest.MoveNext())
                {
                    yield return(null);
                }
            }

            AssetBundleLoadOperation levelLoadRequest = AssetBundleManager.LoadLevelAsync(assetBundleName, sceneName, true);

            if (levelLoadRequest != null)
            {
                while (levelLoadRequest.MoveNext())
                {
                    yield return(null);//request.Current just returns null, so we can do that instead
                }
                AssetBundleManager.UnloadAssetBundle(assetBundleName);
            }
            else
            {
                Debug.Log("Could not load level " + assetBundleName + " Asset Bundle.");
                yield break;
            }
#else
            throw new NotImplementedException("You must enable Asset Bundle Integration to utilize the Asset Bundle Loader.");
#endif
        }
Beispiel #4
0
    void ProcessFinishedOperation(AssetBundleLoadOperation operation)
    {
        AssetBundleDownloadOperation download = operation as AssetBundleDownloadOperation;

        if (download == null)
        {
            return;
        }

        if (string.IsNullOrEmpty(download.error))
        {
#if UNITY_EDITOR
            for (int i = 0; i < editorShaders.Length; i++)
            {
                if (editorShaders[i].Equals(download.assetBundleName))
                {
                    Material mat = download.assetBundle.m_AssetBundle.LoadAsset <Material>(editorMats[i]);
                    mat.shader      = Shader.Find(mat.shader.name);
                    mat.renderQueue = editorRenderQueues[i];
                }
            }
#endif
            m_LoadedAssetBundles.Add(download.assetBundleName, download.assetBundle);
        }
        else
        {
            string msg = string.Format("Failed downloading bundle {0} from {1}: {2}",
                                       download.assetBundleName, download.GetSourceURL(), download.error);
            m_DownloadingErrors.Add(download.assetBundleName, msg);
        }

        m_DownloadingBundles.Remove(download.assetBundleName);
    }
Beispiel #5
0
 static public int Update(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         AssetBundleLoadOperation self = (AssetBundleLoadOperation)checkSelf(l);
         var ret = self.Update();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Beispiel #6
0
    private IEnumerator InitializeLevelAsync(string sceneBundleName, string sceneName, UnityAction SceneLoadDoneCallback, float timedur)
    {
        IsChecking = true;
        StartCoroutine(CheckingDownload());
        yield return(new WaitForSeconds(timedur));

        //		// Load level from assetBundle.
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneBundleName, sceneName, true);

        if (request == null)
        {
            StartCoroutine(InitializeLevelAsync(sceneBundleName, sceneName, SceneLoadDoneCallback, timedur));
            yield break;
        }
        yield return(StartCoroutine(request));

        //        IsChecking = false;
        if (SceneLoadDoneCallback != null)
        {
            SceneLoadDoneCallback();
        }

        isLoading = false;
        PopupAndLoadingScript.instance.HideLoading();
    }
Beispiel #7
0
        IEnumerator LoadChapterSceneAsync(int chapter)
        {
            // This is simply to get the elapsed time for this phase of AssetLoading
            float startTime = Time.realtimeSinceStartup;

            // Load level from assetBundle
            var sceneAssetBundle = "chapter" + chapter;
            var levelName        = "Chapter" + chapter;

            // Simulate the preload for a minimim of x seconds
            yield return(new WaitForSeconds(3));

            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, false);

            if (request == null)
            {
                yield break;
            }
            yield return(StartCoroutine(request));

            // Calculate and display the elapsed time.
            float elapsedTime = Time.realtimeSinceStartup - startTime;

            Debug.Log("Finished loading Chapter scene " + levelName + " in: " + elapsedTime + " seconds");

            // Notify store when scene has loaded
            Unidux.Store.Dispatch(Game.ActionCreator.SceneLoaded(levelName));
        }
        /// <summary>
        /// 异步加载场景
        /// </summary>
        private async Task _LoadScene(string sceneAssetBundle, string levelName, bool isAdditive, Action <float> cbProgress)
        {
            float startTime = Time.realtimeSinceStartup;
            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);

            if (request != null)
            {
                while (request.Progress() < 1f)
                {
                    await waitFrame;
                    cbProgress?.Invoke(request.Progress());
                    if (request.IsDone())
                    {
                        break;
                    }
                }
                cbProgress?.Invoke(1f);
            }

            float elapsedTime = Time.realtimeSinceStartup - startTime;

            Utils.ResetShader(null);
            Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
            Debug.Log("当前场景 " + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
        }
Beispiel #9
0
    private IEnumerator StartLoadLevel(string assetBundleName, string levelName)
    {
        if (!string.IsNullOrEmpty(this.m_currentLevel))
        {
            AssetBundleManager.UnloadAssetBundle(this.m_currentLevel, true);
        }
        yield return(new WaitForEndOfFrame());

#if DEBUG_ASSETBUNDLE
        Debug.Log("---------");
#endif
        SceneManager.LoadScene("empty");
        yield return(new WaitForEndOfFrame());

#if DEBUG_ASSETBUNDLE
        Debug.Log("--- load level asy ---");
#endif
        AssetBundleLoadOperation level = AssetBundleManager.LoadLevelAsync(assetBundleName, levelName);
        yield return(level);

        this.m_currentLevel = assetBundleName;
        if (this.mLoadLevelCallback != null)
        {
            this.mLoadLevelCallback();
            this.mLoadLevelCallback = null;
        }
    }
    IEnumerator WaitInalize(AssetBundleLoadOperation operation, UnityAction onActive)
    {
        yield return(operation);

        if (onActive != null)
        {
            onActive.Invoke();
        }
    }
Beispiel #11
0
    public static void SetpAssetBundleLoadOperation(AssetBundleLoadOperation pAssetBundleLoadOperation)
    {
        if (Instance() == null)
        {
            return;
        }

        Instance().m_pAssetBundleLoadOperation = pAssetBundleLoadOperation;
    }
Beispiel #12
0
    public IEnumerator LoadLevelAsync(string bundleName, string sceneName, bool isAdditive)
    {
        AssetBundleLoadOperation async = AssetBundleManager.LoadLevelAsync(bundleName, sceneName, isAdditive);

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

        yield break;
    }
Beispiel #13
0
	// Load level from the given assetBundle.
	public AssetBundleLoadOperation LoadLevelAsync (string assetBundleName, string levelName, bool isAdditive)
	{
		AssetBundleLoadOperation operation = null;

		LoadAssetBundle (assetBundleName);
		operation = new AssetBundleLoadLevelOperation (assetBundleName, levelName, isAdditive);

		m_InProgressOperations.Add (operation);

		return operation;
	}
Beispiel #14
0
    public IEnumerator LoadScene(string assetBundleName, string scenseName, bool isAddtive)
    {
        AssetBundleManager.UnloadAssetBundle(assetBundleName);
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(assetBundleName, scenseName, true);

        if (request == null)
        {
            yield break;
        }
        yield return(context.StartCoroutine(request));
    }
    // Load level from the given assetBundle.
    public AssetBundleLoadOperation LoadLevelAsync(string a_assetBundleName, string a_levelName, bool a_isAdditive, bool a_allowSceneActivation)
    {
        AssetBundleLoadOperation operation = null;

#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            var levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(a_assetBundleName, a_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 \"" + a_levelName + "\" in " + a_assetBundleName);
                return(null);
            }

            if (a_isAdditive)
            {
                EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
            }
            else
            {
                EditorApplication.LoadLevelInPlayMode(levelPaths[0]);
            }

            operation = new AssetBundleLoadLevelSimulationOperation();
        }
        else
#endif
        {
            var key = AssetToKey(a_assetBundleName, a_levelName);

            AssetBundleLoadOperation inProgressOperation;
            if (m_inProgressOperationsByName.TryGetValue(key, out inProgressOperation))
            {
                var loadLevelOperation = inProgressOperation as AssetBundleLoadLevelOperation;
                if (loadLevelOperation != null)
                {
                    return(loadLevelOperation);
                }
            }

            LoadAssetBundle(a_assetBundleName);
            operation = new AssetBundleLoadLevelOperation(a_assetBundleName, a_levelName, a_isAdditive, a_allowSceneActivation);

            m_inProgressOperationsByName.Add(key, operation);
            m_inProgressOperations.Add(new KeyValuePair <string, AssetBundleLoadOperation>(key, operation));
        }

        return(operation);
    }
Beispiel #16
0
    public IEnumerator LoadLevelAsync(string name)
    {
        Debug.Log("start load: " + name);

        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync("ab_scenes_" + name, name, false);

        if (request == null)
        {
            yield break;
        }

        yield return(StartCoroutine(request));
    }
Beispiel #17
0
        /// <summary>
        /// 加载图片
        /// </summary>
        public void LoadConfig(ResType type, string abName, string assetName = "", Action <AssetBundleData> loadComplete = null)
        {
            AssetBundleLoadOperation operation = null;
            string          abPath             = ResConfig.GetABPath(type, abName);
            AssetBundleData loadedAssetBundle  = GetAssetBundle(abPath);

            if (loadedAssetBundle == null)
            {
                LoadAssetBundle(abPath);
            }
            operation = new AssetBundleLoadAssetOperation(abPath, assetName, typeof(TextAsset), loadComplete);
            listProgressOperations.Add(operation);
        }
    public IEnumerator LoadScene(string levelName)
    {
        Debug.Log("### start LoadScene >> " + levelName);

        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(ASSET_BUNDLE_SCENES, levelName, true);

        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));

        Debug.Log("finish LoadScene >> " + levelName);
    }
Beispiel #19
0
    /*
     * summary
     * 씬 로드시 로드되어있는 씬일 경우 ActiveScene으로 설정
     * 씬 로드가 안되어있을 경우 씬의 전환을 이룸.
     * summary
     */

    public IEnumerator LoadScene(string sceneName, bool isLoading = true, bool isImediately = true, bool isAdditive = true)
    {
        Debug.LogFormat("LoadScene {0}", sceneName);

        // Scene in sceneNameList
        if (_sceneNameList.Contains(sceneName))
        {
            foreach (var scene in _sceneNameList)
            {
                if (scene == sceneName)
                {
                    Debug.Log("ActiveScene Change : " + sceneName);
                    SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName));
                    yield break;
                }
            }
        }
        else
        {
            yield return(new WaitForSeconds(0.1f));

            //LoadLevelAsync함수를 통해 에셋을 로드대기 시키고 AssetBundleLoadOperation생성후 반환
            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(AssetManager.Instance._assetBundleKeys[ASSET_TYPE.GAME_SCENES], sceneName, isAdditive);
            if (request == null)
            {
                yield break;
            }

            if (isLoading)
            {
                LoadingBarScript loading = GameObject.Find("Script").GetComponent <LoadingBarScript>();

                StartCoroutine(loading.SetLoadingProgressBar(request));
            }

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

            if (isImediately)
            {
                SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName));
                Debug.Log("씬 활성화 : " + SceneManager.GetActiveScene().name);
            }

            _sceneNameList.Add(sceneName);
        }
    }
Beispiel #20
0
 private void Update()
 {
     for (int i = 0; i < m_InProgressOperations.Count;)
     {
         AssetBundleLoadOperation operation = m_InProgressOperations[i];
         if (operation.Update())
         {
             i++;
         }
         else
         {
             m_InProgressOperations.RemoveAt(i);
             ProcessFinishedOperation(operation);
         }
     }
 }
Beispiel #21
0
    protected IEnumerator InitializeLevelAsync(string sceneAssetBundle, string levelName, bool isAdditive)
    {
        float startTime = Time.realtimeSinceStartup;

        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);

        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));

        float elapsedTime = Time.realtimeSinceStartup - startTime;

        Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
    }
    protected IEnumerator LoadLevel(string assetBundleName, string levelName, bool isAdditive)
    {
        Debug.Log("Start to load scene " + levelName + " at frame " + Time.frameCount);

        // Load level from assetBundle.
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(assetBundleName, levelName, isAdditive);

        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));

        // This log will only be output when loading level additively.
        Debug.Log("Finish loading scene " + levelName + " at frame " + Time.frameCount);
    }
Beispiel #23
0
        protected IEnumerator InitializeLevelAsync(AssetsTableScriptableObject.AssetEntry assetEntry, bool isAdditive = false)
        {
            //float startTime = Time.realtimeSinceStartup;

            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(assetEntry.AssetBundleName, assetEntry.AssetName, isAdditive);

            if (request == null)
            {
                yield break;
            }

            yield return(StartCoroutine(request));

            //Calculate and display the elapsed time.
            //float elapsedTime = Time.realtimeSinceStartup - startTime;
            //Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
        }
Beispiel #24
0
    private static void LoadResourceInternalImp(string assetName, string bundleName, Hoba.Action <UnityObject> onLoadFinish, bool needInstantiate)
    {
        LoadAssetBundle(bundleName);

        AssetBundleLoadOperation operation = null;

        if (string.IsNullOrEmpty(assetName))
        {
            operation = new AssetBundleLoadBundleOperation(bundleName, onLoadFinish);
        }
        else
        {
            operation = new AssetBundleLoadAssetOperation(assetName, bundleName, onLoadFinish, needInstantiate);
        }

        _InProgressOperations.Add(operation);
    }
Beispiel #25
0
    private void ProcessFinishedOperation(AssetBundleLoadOperation operation)
    {
        AssetBundleDownloadOperation download = operation as AssetBundleDownloadOperation;

        if (download == null)
        {
            return;
        }
        if (download.error == null)
        {
            m_LoadedAssetBundles.Add(download.assetBundleName, download.assetBundle);
        }
        else
        {
            string msg = string.Format("Failed downloading bundle {0} from {1}", download.assetBundleName, download.error);
            m_DownloadingErrors.Add(download.assetBundleName, msg);
        }
        m_DownloadingBundles.Remove(download.assetBundleName);
    }
Beispiel #26
0
    protected IEnumerator InitializeLevelAsync(string levelName, bool isAdditive)
    {
        // This is simply to get the elapsed time for this phase of AssetLoading.
        float startTime = Time.realtimeSinceStartup;

        // Load level from assetBundle.
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(assetBundleSceneName, levelName, isAdditive);

        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));

        // Calculate and display the elapsed time.
        float elapsedTime = Time.realtimeSinceStartup - startTime;

        Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
    }
Beispiel #27
0
    public static AssetBundleLoadOperation LoadLevelAsync(string assetBundleName, string levelName)
    {
        AssetBundleLoadOperation operation = null;

#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            operation = new AssetBundleLoadLevelSimulationOperation(assetBundleName, levelName);
        }
        else
#endif
        {
            assetBundleName = RemapVariantName(assetBundleName);
            LoadAssetBundle(assetBundleName, true);
            operation = new AssetBundleLoadLevelOperation(assetBundleName, levelName);
            m_InProgressOperations.Add(operation);
        }
        return(operation);
    }
Beispiel #28
0
    public IEnumerator LoadLevelAsync(string levelName, bool isAdditive)
    {
        Debug.Log("LoadLevelAsync:" + levelName);
        if (_ResFromBundle)
        {
            string sceneAssetBundle = "Scene/" + levelName + ".common";

            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle.ToLower(), levelName, isAdditive);
            if (request == null)
            {
                yield break;
            }
            yield return(StartCoroutine(request));
        }
        else
        {
            yield return(SceneManager.LoadSceneAsync(levelName, isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single));
        }
    }
Beispiel #29
0
    // Use this for initialization
    IEnumerator Start()
    {
        string dataPath = Application.dataPath;
        WWW    www;

#if UNITY_EDITOR
        www = new WWW("file:///" + dataPath + "/config.txt");
#elif UNITY_WEBPLAYER
        www = new WWW(dataPath + "/config.txt");
#endif
        yield return(www);

        Debug.Log(www.text);
        if (www.text == "")
        {
            Debug.Log("NULL URL");
        }
        else
        {
            url = www.text;
        }

        yield return(StartCoroutine(BundleManager.Initialize()));

        isManifestOK = true;
        if (waitingScreen == null)
        {
            waitingScreen = Instantiate(waitingPrefab) as GameObject;
        }
        DontDestroyOnLoad(waitingScreen);
        waitingScreen.SetActive(false);
        Instantiate(eventManager);
        Instantiate(instructionView);
        Instantiate(dataStorage);

        AssetBundleLoadOperation request = BundleManager.LoadLevelAsync(levelBundleName, levelName, false);
        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));
    }
 /// <summary>
 /// 加载依赖关系
 /// </summary>
 /// <param name="onMenuLoad"></param>
 private void LoadMenu(UnityAction onMenuLoad)
 {
     if (menuLoaded)
     {
         onMenuLoad();
     }
     else
     {
         UnityAction newOnMenuLoad = () =>
         {
             menuLoaded = true;
             if (onMenuLoad != null)
             {
                 onMenuLoad.Invoke();
             }
         };
         AssetBundleLoadOperation initopera = activeLoader.Initialize();
         StartCoroutine(WaitInalize(initopera, newOnMenuLoad));
     }
 }
        void ProcessFinishedOperation(AssetBundleLoadOperation operation)
        {
            AssetBundleDownloadOperation download = operation as AssetBundleDownloadOperation;
            if (download == null)
                return;

            if (download.error == null)
                m_LoadedAssetBundles.Add(download.assetBundleName, download.assetBundle);
            else
            {
                string msg = string.Format("Failed downloading bundle {0} from {1}: {2}",
                        download.assetBundleName, download.GetSourceURL(), download.error);
                m_DownloadingErrors.Add(download.assetBundleName, msg);
            }

            m_DownloadingBundles.Remove(download.assetBundleName);
        }