Exemplo n.º 1
0
        // 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;
                if (string.IsNullOrEmpty(levelName))
                {
                    levelPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                }
                else
                {
                    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);
        }
Exemplo n.º 2
0
        protected IEnumerator LoadLevel(string assetBundleName, string levelName, bool isAdditive)
        {
#if ASSET_LOG
            Debug.Log("Start to load scene " + levelName + " at frame " + Time.frameCount);
#endif

            // Load level from assetBundle.
            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(assetBundleName, levelName, isAdditive);
            if (request == null)
            {
                yield break;
            }
            yield return(StartCoroutine(request));

#if ASSET_LOG
            // This log will only be output when loading level additively.
            Debug.Log("Finish loading scene " + levelName + " at frame " + Time.frameCount);
#endif
        }