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); } }); }
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); }
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);