Exemplo n.º 1
0
        private static void LoadAssetFromAssetBundle <T>(string path, Type type, System.Action <T> callback) where T : UnityEngine.Object
        {
            string bundleName = AssetBundlePath.FileToBundleName(path);

            LoadAssetBundle(bundleName, (AssetBundle bundle) =>
            {
                if (bundle != null)
                {
                    string assetName           = AssetBundlePath.FileToAssetName(path);
                    AssetBundleRequest request = bundle.LoadAssetAsync(assetName, type);
                    request.completed         += (AsyncOperation operation) =>
                    {
                        T asset = request.asset as T;
                        if (asset == null)
                        {
                            AssetBundleLoaderDebug.LogError("Asset loading faild in bundle" + Environment.NewLine +
                                                            "bundle name: " + bundleName + Environment.NewLine +
                                                            "asset name: " + assetName);
                        }
                        callback?.Invoke(asset);
                    };
                }
                else
                {
                    callback?.Invoke(null);
                }
            });
        }
Exemplo n.º 2
0
        private static void LoadSceneInEditor(string path, System.Action <Scene> callback, LoadSceneMode loadSceneMode)
        {
            Scene scene = SceneManager.GetSceneByName(AssetBundlePath.FileToAssetName(path));

            if (!path.EndsWith(".unity"))
            {
                path += ".unity";
            }
            path = Path.Combine("Assets", path);
            if (scene == default)
            {
                if (Application.isPlaying)
                {
                    LoadSceneByPathInEditorPlayMode(path, callback, loadSceneMode);
                }
                else
                {
                    LoadSceneByPathInEditor(path, callback, loadSceneMode);
                }
            }
            else
            {
                SceneManager.SetActiveScene(scene);
                callback?.Invoke(scene);
            }
        }
Exemplo n.º 3
0
 private static void LoadAssetInEditor <T>(string path, Type type, System.Action <T> callback) where T : UnityEngine.Object
 {
     UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(Path.Combine("Assets", path), type);
     if (asset == null)
     {
         string assetName = AssetBundlePath.FileToAssetName(path);
         AssetBundleLoaderDebug.LogError("Asset loading faild in editor" + Environment.NewLine +
                                         "path: " + path + Environment.NewLine +
                                         "asset name: " + assetName);
     }
     callback?.Invoke(asset as T);
 }
Exemplo n.º 4
0
 private static void LoadSceneByPathInEditorPlayMode(string path, System.Action <Scene> callback, LoadSceneMode loadSceneMode)
 {
     UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(path, new LoadSceneParameters(loadSceneMode))
     .completed += (AsyncOperation request) =>
     {
         Scene scene = SceneManager.GetSceneByPath(path);
         if (scene != default)
         {
             AssetBundleLoaderDebug.Log("Scene loading succeeded " + scene.name);
             SceneManager.SetActiveScene(scene);
             callback?.Invoke(scene);
         }
         else
         {
             AssetBundleLoaderDebug.LogError("Scene loading faild " + AssetBundlePath.FileToAssetName(path).Replace(".unity", ""));
             callback?.Invoke(default);