// Load asset from the given assetBundle. // // *********** 주요 사용하는 함수 *********** static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle"); AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return(null); } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { assetBundleName = RemapVariantName(assetBundleName); LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type); m_InProgressOperations.Add(operation); } return(operation); }
public static void LoadAllAssetPostHook(ref AssetBundleLoadAssetOperation __result, string assetBundleName, Type type, string manifestAssetBundleName = null) { if (assetBundleName != null) { if (assetBundleName.StartsWith("sound/data/systemse/brandcall/") || assetBundleName.StartsWith("sound/data/systemse/titlecall/")) { string dir = $@"{Paths.PluginPath}\introclips"; if (!Directory.Exists(dir)) { return; } var files = Directory.GetFiles(dir, "*.wav"); if (files.Length == 0) { return; } var path = files[UnityEngine.Random.Range(0, files.Length - 1)]; var audioClip = ResourceRedirector.AssetLoader.LoadAudioClip(path, AudioType.WAV); __result = new AssetBundleLoadAssetOperationSimulation(audioClip); } } }
public static bool HandleAsset(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { if (assetName.StartsWith("bgm") && assetName.Length > 4) { string path; switch ((BGM)int.Parse(assetName.Remove(0, 4))) { case BGM.Title: default: path = $"{BepInEx.Common.Utility.PluginsDirectory}\\title.wav"; break; case BGM.Custom: path = $"{BepInEx.Common.Utility.PluginsDirectory}\\custom.wav"; break; } if (File.Exists(path)) { BepInLogger.Log($"Loading {path}"); result = new AssetBundleLoadAssetOperationSimulation(AssetLoader.LoadAudioClip(path, AudioType.WAV)); return(true); } } result = null; return(false); }
protected bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { string zipPath = $"{manifestAssetBundleName ?? "abdata"}/{assetBundleName.Replace(".unity3d", "", StringComparison.OrdinalIgnoreCase)}/{assetName}"; if (type == typeof(Texture2D)) { zipPath = $"{zipPath}.png"; var tex = GetPng(zipPath); if (tex != null) { result = new AssetBundleLoadAssetOperationSimulation(tex); return(true); } } if (BundleManager.TryGetObjectFromName(assetName, assetBundleName, type, out UnityEngine.Object obj)) { result = new AssetBundleLoadAssetOperationSimulation(obj); return(true); } result = null; return(false); }
/// <summary> /// 异步从AssetBundle加载资源,加载完成后可以调用UnloadAssetBundle提前卸载AssetBundle /// </summary> /// <returns>可以使用协程等待结果或者检查IsDone</returns> public static AMLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { AMLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return(null); } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPaths[0], type); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { LoadAssetBundle(assetBundleName, false); operation = new AssetBundleLoadAssetOperationSecond(assetBundleName, assetName, type); m_inProgressOperations.Add(operation); } return(operation); }
protected bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { if (type == typeof(ScenarioData)) { string scenarioPath = Path.Combine(scenarioDir, Path.Combine(assetBundleName, $"{assetName}.csv")).Replace('/', '\\').Replace(".unity3d", "").Replace(@"adv\scenario\", ""); if (File.Exists(scenarioPath)) { var rawData = ManualLoadAsset <ScenarioData>(assetBundleName, assetName, manifestAssetBundleName); rawData.list.Clear(); foreach (IEnumerable <string> line in SplitAndEscape(File.ReadAllText(scenarioPath, Encoding.UTF8))) { string[] data = line.ToArray(); string[] args = new string[data.Length - 4]; Array.Copy(data, 4, args, 0, args.Length); ScenarioData.Param param = new ScenarioData.Param(bool.Parse(data[3]), (Command)int.Parse(data[2]), args); param.SetHash(int.Parse(data[0])); rawData.list.Add(param); } result = new AssetBundleLoadAssetOperationSimulation(rawData); return(true); } } else if (type == typeof(ExcelData)) { string communicationPath = Path.Combine(communicationDir, Path.Combine(assetBundleName.Replace("communication/", ""), $"{assetName}.csv")).Replace('/', '\\').Replace(".unity3d", ""); if (File.Exists(communicationPath)) { var rawData = ManualLoadAsset <ExcelData>(assetBundleName, assetName, manifestAssetBundleName); rawData.list.Clear(); foreach (IEnumerable <string> line in SplitAndEscape(File.ReadAllText(communicationPath, Encoding.UTF8))) { ExcelData.Param param = new ExcelData.Param() { list = line.ToList() }; rawData.list.Add(param); } result = new AssetBundleLoadAssetOperationSimulation(rawData); return(true); } } result = null; return(false); }
protected bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { string zipPath = $"{manifestAssetBundleName ?? "abdata"}/{assetBundleName.Replace(".unity3d", "")}/{assetName}"; if (type == typeof(Texture2D)) { zipPath = $"{zipPath}.png"; foreach (var archive in Archives) { var entry = archive.GetEntry(zipPath); if (entry != null) { var stream = archive.GetInputStream(entry); result = new AssetBundleLoadAssetOperationSimulation(ResourceRedirector.AssetLoader.LoadTexture(stream, (int)entry.Size)); return(true); } } } if (BundleManager.TryGetObjectFromName(assetName, assetBundleName, type, out UnityEngine.Object obj)) { result = new AssetBundleLoadAssetOperationSimulation(obj); return(true); } result = null; return(false); }
public static AssetBundleManager.BundlePack ManifestAdd( string manifestAssetBundleName) { if (AssetBundleManager.m_ManifestBundlePack.ContainsKey(manifestAssetBundleName)) { return((AssetBundleManager.BundlePack)null); } AssetBundleManager.BundlePack bundlePack = new AssetBundleManager.BundlePack(); AssetBundleManager.m_ManifestBundlePack.Add(manifestAssetBundleName, bundlePack); LoadedAssetBundle loadedAssetBundle = AssetBundleManager.LoadAssetBundle(manifestAssetBundleName, false, manifestAssetBundleName); if (loadedAssetBundle == null) { AssetBundleManager.m_ManifestBundlePack.Remove(manifestAssetBundleName); return((AssetBundleManager.BundlePack)null); } AssetBundleLoadAssetOperationSimulation operationSimulation = new AssetBundleLoadAssetOperationSimulation(loadedAssetBundle.m_AssetBundle.LoadAsset("AssetBundleManifest", typeof(AssetBundleManifest))); if (operationSimulation.IsEmpty()) { AssetBundleManager.m_ManifestBundlePack.Remove(manifestAssetBundleName); return((AssetBundleManager.BundlePack)null); } bundlePack.AssetBundleManifest = operationSimulation.GetAsset <AssetBundleManifest>(); return(bundlePack); }
public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return(null); } UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { assetBundleName = RemapVariantName(assetBundleName); LoadAssetBundleAsync(assetBundleName, true, true); operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type); m_InProgressOperations.Add(operation); } return(operation); }
public static void LoadAllAssetPostHook(ref AssetBundleLoadAssetOperation __result, string assetBundleName, Type type, string manifestAssetBundleName = null) { //BepInLogger.Log($"{assetBundleName} : {type.FullName} : {manifestAssetBundleName ?? ""}"); if (assetBundleName == "sound/data/systemse/brandcall/00.unity3d" || assetBundleName == "sound/data/systemse/titlecall/00.unity3d") { string dir = $"{Paths.PluginPath}\\introclips"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var files = Directory.GetFiles(dir, "*.wav"); if (files.Length == 0) { return; } List <UnityEngine.Object> loadedClips = new List <UnityEngine.Object>(); foreach (string path in files) { loadedClips.Add(AssetLoader.LoadAudioClip(path, AudioType.WAV)); } __result = new AssetBundleLoadAssetOperationSimulation(loadedClips.ToArray()); } }
// Load asset from the given assetBundle. public AssetBundleLoadAssetOperation LoadAssetAsync(string a_assetBundleName, string a_assetName, Type a_type) { if (string.IsNullOrEmpty(a_assetBundleName) || string.IsNullOrEmpty(a_assetName)) { return(null); } AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] paths = null; if (!s_cachedPathsForBundle.TryGetValue(a_assetBundleName, out paths)) { paths = AssetDatabase.GetAssetPathsFromAssetBundle(a_assetBundleName); s_cachedPathsForBundle.Add(a_assetBundleName, paths); } //var assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(a_assetBundleName, a_assetName); if (!paths.Contains(a_assetName)) { Debug.LogError("There is no asset with name \"" + a_assetName + "\" in " + a_assetBundleName); return(null); } var target = AssetDatabase.LoadAssetAtPath(a_assetName, a_type); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { var key = AssetToKey(a_assetBundleName, a_assetName); AssetBundleLoadOperation inProgressOperation; if (m_inProgressOperationsByName.TryGetValue(key, out inProgressOperation)) { if (inProgressOperation is AssetBundleLoadAssetOperation) { return(inProgressOperation as AssetBundleLoadAssetOperation); } } LoadAssetBundle(a_assetBundleName); operation = new AssetBundleLoadAssetOperationFull(a_assetBundleName, a_assetName, a_type); //Debug.Log("Adding operation " + a_assetName); m_inProgressOperationsByName.Add(key, operation); m_inProgressOperations.Add(new KeyValuePair <string, AssetBundleLoadOperation>(key, operation)); } return(operation); }
// Load asset from the given assetBundle. static public AssetBundleLoadAssetOperation LoadAssetAsync (string assetBundleName, string assetName, System.Type type) { AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor == LoadMode.AssetBundleName) { //GetAssetPathsFromAssetBundleAndAssetName接口对大小写敏感 assetBundleName = assetBundleName.ToLower(); assetName = assetName.ToLower(); Debug.LogError("AssetBudle" + AssetDatabase.GetAllAssetBundleNames()); string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return null; } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation (target); } else if (SimulateAssetBundleInEditor == LoadMode.LoadAssetAtPath) { Object target = null; for (int i = 0; i < extension.Length; i++) { //去掉后缀 string bundleName = assetBundleName.Replace(System.IO.Path.GetExtension(assetBundleName), extension[i]); //直接预制体加载 target = AssetDatabase.LoadAssetAtPath<Object>(bundleName); if (target != null) break; } operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { LoadAssetBundle (assetBundleName); operation = new AssetBundleLoadAssetOperationFull (assetBundleName, assetName, type); m_InProgressOperations.Add (operation); } return operation; }
protected bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { string zipPath = $"{manifestAssetBundleName ?? "abdata"}/{assetBundleName.Replace(".unity3d", "", StringComparison.OrdinalIgnoreCase)}/{assetName}"; if (type == typeof(Texture2D)) { zipPath = $"{zipPath}.png"; //Only search the archives for a .png that can actually be found if (PngList.TryGetValue(zipPath, out ZipFile archive)) { var entry = archive.GetEntry(zipPath); if (entry != null) { var stream = archive.GetInputStream(entry); var tex = ResourceRedirector.AssetLoader.LoadTexture(stream, (int)entry.Size); if (zipPath.Contains("clamp")) { tex.wrapMode = TextureWrapMode.Clamp; } else if (zipPath.Contains("repeat")) { tex.wrapMode = TextureWrapMode.Repeat; } result = new AssetBundleLoadAssetOperationSimulation(tex); return(true); } } } if (BundleManager.TryGetObjectFromName(assetName, assetBundleName, type, out UnityEngine.Object obj)) { result = new AssetBundleLoadAssetOperationSimulation(obj); return(true); } result = null; return(false); }
// Load asset from the given assetBundle. static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type, bool bSingle = true) { AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { SampleDebuger.Log("LoadAssetAsync " + assetBundleName); operation = new AssetBundleLoadAssetOperationSimulation(assetBundleName, assetName, bSingle); } else #endif { LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type, bSingle); m_InProgressOperations.Add(operation); } return operation; }
// Load asset from the given assetBundle. static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { Debug.Log("Loading " + assetName + " from " + assetBundleName + " bundle"); AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return null; } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { try { LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type); m_InProgressOperations.Add(operation); } catch { string log = string.Format("There is no asset with name {0} in {1}", assetName, assetBundleName); Debug.LogError(log); //Fabric.Crashlytics.Crashlytics.Log(log); return null; } } return operation; }
public static bool HandleAsset(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { if (assetName.StartsWith("bgm") && assetName.Length > 4) { int bgmTrack = int.Parse(assetName.Remove(0, 4)); var path = Utility.CombinePaths(Utility.PluginsDirectory, "bgm", $"BGM{bgmTrack:00}.ogg"); if (File.Exists(path)) { Logger.Log(LogLevel.Info, $"Loading BGM track \"{(BGM)bgmTrack}\" from {path}"); result = new AssetBundleLoadAssetOperationSimulation(AudioLoader.LoadVorbis(path)); return(true); } } result = null; return(false); }
// Starts a load operation for an asset from the given asset bundle. static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle"); AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return null; } // @TODO: Now we only get the main object from the first asset. Should consider type also. UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { assetBundleName = RemapVariantName(assetBundleName); LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type); m_InProgressOperations.Add(operation); } return operation; }
public static bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result) { string TranslationPath = Path.Combine(DynamicTranslator.dirTranslation, Path.Combine(assetBundleName, assetName)).Replace('/', '\\').Replace(".unity3d", ""); if (type == typeof(ScenarioData)) { if (Directory.Exists(TranslationPath) || File.Exists(TranslationPath + ".csv")) { var rawData = ManualLoadAsset <ScenarioData>(assetBundleName, assetName, manifestAssetBundleName); //Clear the data and load the new data from the .csv, if there is one. if (File.Exists(TranslationPath + ".csv")) { rawData.list.Clear(); foreach (var line in SplitAndEscape(File.ReadAllText(TranslationPath + ".csv", Encoding.UTF8))) { var data = line.ToArray(); var args = new string[data.Length - 4]; Array.Copy(data, 4, args, 0, args.Length); var param = new ScenarioData.Param(bool.Parse(data[3]), (Command)int.Parse(data[2]), args); param.SetHash(int.Parse(data[0])); rawData.list.Add(param); } } //Read any .txt translations and substitute translated text if (Directory.Exists(TranslationPath)) { foreach (var param in rawData.list) { if (param.Command == Command.Text) { for (int i = 0; i < param.Args.Count(); i++) { param.Args[i] = TranslateTextFromFolder(param.Args[i], TranslationPath); } } } } result = new AssetBundleLoadAssetOperationSimulation(rawData); return(true); } } else if (type == typeof(ExcelData)) { if (Directory.Exists(TranslationPath) || File.Exists(TranslationPath + ".csv")) { var rawData = ManualLoadAsset <ExcelData>(assetBundleName, assetName, manifestAssetBundleName); //Clear the data and load the new data from the .csv, if there is one. if (File.Exists(TranslationPath + ".csv")) { rawData.list.Clear(); foreach (var line in SplitAndEscape(File.ReadAllText(TranslationPath + ".csv", Encoding.UTF8))) { var list = line.ToList(); var param = new ExcelData.Param(); param.list = list; rawData.list.Add(param); } } //Read any .txt translations and substitute translated text if (Directory.Exists(TranslationPath)) { foreach (var param in rawData.list) { for (int i = 0; i < param.list.Count; i++) { param.list[i] = TranslateTextFromFolder(param.list[i], TranslationPath); } } } result = new AssetBundleLoadAssetOperationSimulation(rawData); return(true); } } result = null; return(false); }
// Load asset from the given assetBundle. public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); foreach (var path in assetPaths) { Debuger.Log("LoadAssetAsync " + path); } // if (assetPaths.Length == 0) // { // Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); // return null; // } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation (target); } else #endif { LoadAssetBundle (assetBundleName); operation = new AssetBundleLoadAssetOperationFull (assetBundleName, assetName, type); m_InProgressOperations.Add (operation); } return operation; }