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); } }
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 LoadAllAssetsFromAssetBundle <T>(string path, Type type, System.Action <T[]> callback) where T : UnityEngine.Object { string bundleName = AssetBundlePath.DirectoryToBundleName(path); LoadAssetBundle(bundleName, (AssetBundle bundle) => { if (bundle != null) { AssetBundleRequest request = bundle.LoadAllAssetsAsync(type); request.completed += (AsyncOperation operation) => { UnityEngine.Object[] allAssets = request.allAssets; T[] assets = new T[allAssets.Length]; for (int i = 0; i < allAssets.Length; i++) { assets[i] = allAssets[i] as T; } callback?.Invoke(assets); }; } else { callback?.Invoke(new T[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); }
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);