Beispiel #1
0
    protected IEnumerator LoadLevel(string assetBundleName, string levelName, Action fn)
    {
        // Debug.Log("Start to load scene " + levelName + " at frame " + Time.frameCount);
        // Load level from assetBundle.
        AssetBundleLoadBaseOperation request = AssetBundleManager.LoadLevelAsync(assetBundleName, levelName, false);

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

        if (fn != null)
        {
            fn();
        }
    }
Beispiel #2
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;
    }