public static void Execute(UnityEditor.BuildTarget target) { string platform = AssetBundleController.GetPlatformName(target); Execute(platform); AssetDatabase.Refresh(); }
private static void SetupSearchPatch(ref object datas, ref string search, ref Action <object, AssetBundleController, CustomDataListLoader> ___action) { int num = searchValue.LastIndexOf("/"); var text = searchValue.Substring(0, num); if (!Directory.Exists(GlobalData.assetBundlePath + "/list/" + text)) { return; } foreach (var text3 in Directory.GetFiles(GlobalData.assetBundlePath + "/list/" + text, search + "_Mlist.txt")) { Logger.LogInfo("Load Mlist:" + text3); StreamReader streamReader = new StreamReader(new FileStream(text3, FileMode.Open)); string assetBundleName = streamReader.ReadLine(); string contents = streamReader.ReadToEnd(); string tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, contents); CustomDataListLoader customDataListLoader = new CustomDataListLoader(); customDataListLoader.Load(tempFileName); File.Delete(tempFileName); AssetBundleController assetBundleController2 = new AssetBundleController(); assetBundleController2.OpenFromFile(GlobalData.assetBundlePath, assetBundleName); ___action(datas, assetBundleController2, customDataListLoader); assetBundleController2.Close(false); } }
public static void Execute(UnityEditor.BuildTarget target) { string platfrom = AssetBundleController.GetPlatformName(target); Execute(platfrom, "StreamingAssets/clientxml2/"); AssetDatabase.Refresh(); }
public static void Execute(UnityEditor.BuildTarget target) { allmat = AssetDatabase.FindAssets("t:Prefab", folders); maxNum = allmat.Length; curNum = 0; _target = target; SavePath = AssetBundleController.GetPlatformPath(_target); for (int i = 0; i < maxNum; i++) { curNum = i; path = AssetDatabase.GUIDToAssetPath(allmat[curNum]); if (path.Contains("3D")) { continue; } Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object)); path = SavePath + obj.name; path += ".assetbundle"; Debug.Log(path); BuildPipeline.BuildAssetBundle(obj, null, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, _target); } EditorUtility.DisplayDialog("", "一键打包", "OK"); //VisualAutuPack win = (VisualAutuPack)EditorWindow.GetWindowWithRect(typeof(VisualAutuPack), new Rect(Screen.width / 2 - 300, Screen.height / 2, 600, 400), true, "打包中"); }
public static void ExecuteMd5(UnityEditor.BuildTarget target, string md5FilePath) { string platfrom = AssetBundleController.GetPlatformName(target); Execute(platfrom, md5FilePath); AssetDatabase.Refresh(); }
public static void ExecuteDecrypt(UnityEditor.BuildTarget target) { //清空一下缓存 Caching.CleanCache(); string platfrom = AssetBundleController.GetPlatformName(target); string dir = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platfrom); foreach (string filePath in Directory.GetFiles(dir)) { if (filePath.Contains(".meta") || filePath.Contains("VersionMD5") || filePath.Contains(".xml") || filePath.Contains(".assetbundle")) { continue; } string key = filePath.Substring(dir.Length + 1, filePath.Length - dir.Length - 1); FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); byte[] fileData = new byte[file.Length]; byte[] NewHeader = System.Text.Encoding.UTF8.GetBytes("DreamfactionGame"); byte[] NewEnd = System.Text.Encoding.UTF8.GetBytes("zmy"); byte[] buff = new byte[(int)file.Length - NewHeader.Length - NewEnd.Length]; file.Read(fileData, 0, (int)file.Length); for (int i = 0; i < fileData.Length; i++) { if (i >= 0 && i < NewHeader.Length) { //buff[i] = NewHeader[i]; //buff[i] += (byte)i; } else if (i >= NewHeader.Length && i < fileData.Length - NewEnd.Length) { buff[i - NewHeader.Length] = fileData[i]; buff[i - NewHeader.Length] -= 1; } else if (i >= fileData.Length - NewEnd.Length && i < fileData.Length) { //buff[i] = NewEnd[i - fileData.Length]; } } file.Flush(); file.Close(); fileData = null; key = key.Substring(0, key.LastIndexOf('.')); key += ".dec"; FileStream stream = new FileStream(dir + "/" + key, FileMode.Create); stream.Write(buff, 0, buff.Length); stream.Flush(); stream.Close(); buff = null; } AssetDatabase.Refresh(); }
public static void ExecuteMac() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.StandaloneOSXUniversal; window.Show(); }
public static void ExecuteWebPlayer() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.WebPlayer; window.Show(); }
public static AssetBundleController New_OpenFromFile(string directory, string assetBundleName) { AssetBundleController controller = new AssetBundleController(); if (controller.OpenFromFile(directory, assetBundleName)) { return(controller); } return(null); }
public static void Execute(UnityEditor.BuildTarget target) { string SavePath = AssetBundleController.GetPlatformPath(target); Object obj = AssetDatabase.LoadAssetAtPath(SavePath + "VersionNum/VersionNum.xml", typeof(Object)); BuildPipeline.BuildAssetBundle(obj, null, SavePath + "VersionNum/VersionNum.assetbundle", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, target); AssetDatabase.Refresh(); }
private static bool LoadAssetPatch(AssetBundleController __instance, ref string assetName, ref object __result) { if (__instance.assetBundleName.Contains("thumnbnail/thumbnail_") || __instance.assetBundleName.Contains("thumnbnail/thumnbs_")) { string text = __instance.directory + "/thumnbnail_R/" + assetName + ".png"; if (File.Exists(text)) { Logger.LogInfo("Load thumb:" + text); __result = LoadPNG(text); return(false); } } return(true); }
private static bool SetupPatch(ref AssetBundleController abc, ref Action <object, AssetBundleController, CustomDataListLoader> ___action, ref object datas) { string text = abc.directory + "/list/" + abc.assetBundleName + "_list.txt"; if (File.Exists(text)) { Logger.LogInfo("Load list:" + text); CustomDataListLoader customDataListLoader = new CustomDataListLoader(); customDataListLoader.Load(text); ___action(datas, abc, customDataListLoader); return(false); } return(true); }
private static bool SetupPrefix(object __instance, ref object datas, ref AssetBundleController abc) { string text = BepInEx.Utility.CombinePaths(MoreSlotID.ModFolder, "list", abc.assetBundleName, "_list.txt"); if (File.Exists(text)) { Console.WriteLine("Load list:" + text); CustomDataListLoader customDataListLoader = new CustomDataListLoader(); customDataListLoader.Load(text); var args = new Type[] { datas.GetType(), typeof(AssetBundleController), typeof(CustomDataListLoader) }; Traverse.Create(__instance).Field("action").Method("Invoke", args).GetValue(datas, abc, customDataListLoader); return(false); } return(true); }
public static void ExecuteAnim(UnityEditor.BuildTarget target) { allmat = AssetDatabase.FindAssets("t:AnimationClip", folders); Dictionary <string, List <Object> > animMap = new Dictionary <string, List <Object> >(); string strKey = string.Empty; SavePath = AssetBundleController.GetPlatformPath(target); for (int i = 0; i < allmat.Length; i++) { path = AssetDatabase.GUIDToAssetPath(allmat[i]); if (path.Contains("Models/Animations") == false) { continue; } Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object)); strKey = path.Split('/')[3]; if (animMap.ContainsKey(strKey) == false) { List <Object> animObj = new List <Object>(); animObj.Clear(); animMap.Add(strKey, animObj); animMap[strKey].Add(obj); } else { animMap[strKey].Add(obj); } } foreach (KeyValuePair <string, List <Object> > item in animMap) { StringBuilder animName = new StringBuilder(); animName.Append(item.Key); animName.Append("_Anim"); string exportPate = SavePath + animName.ToString() + ".assetbundle"; Object[] list = item.Value.ToArray(); BuildPipeline.BuildAssetBundle(null, list, exportPate, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, target); } EditorUtility.DisplayDialog("", "一键所有动作组件bundle", "OK"); AssetDatabase.Refresh(); }
private static void LoadMods(Dictionary <int, object> datas, ref string search, Action <Dictionary <int, object>, AssetBundleController, CustomDataListLoader> ___action) { var dir = ""; var filter = ""; var lastSlash = search.LastIndexOf("/", StringComparison.Ordinal); if (lastSlash != -1) { dir = search.Substring(0, lastSlash); filter = search.Remove(0, lastSlash + 1); } foreach (var folder in modFolders) { var abdataDir = Path.Combine(folder, "abdata"); var listDir = BepInEx.Utility.CombinePaths(abdataDir, "list", dir); if (Directory.Exists(listDir)) { foreach (var listPath in Directory.GetFiles(listDir, filter + "_Mlist.txt")) { using (var fileStream = new FileStream(listPath, FileMode.Open)) using (var streamReader = new StreamReader(fileStream)) { var assetBundleName = streamReader.ReadLine(); var listLoader = new CustomDataListLoader(); Traverse.Create(listLoader).Method("Load", new[] { typeof(TextReader) }).GetValue(streamReader); var abc = new AssetBundleController(); abc.OpenFromFile(Path.Combine(folder, "abdata"), assetBundleName); var count = datas.Count; ___action(datas, abc, listLoader); for (int i = count; i < datas.Count; i++) { var prefabData = (ItemDataBase)datas.Values.ElementAt(i); prefabData.assetbundleDir = abdataDir; } abc.Close(); } } } } }
void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } //DontDestroyOnLoad(gameObject); loadingCanvas = this.GetComponentInChildren <CanvasGroup>(); loadingCanvas.gameObject.SetActive(false); }
/// <summary> /// 版本文件的assetbundle文件打包 /// </summary> /// <param name="target">目标平台</param> public static void Execute(UnityEditor.BuildTarget target) { string assetPath = "Assets/" + CreateMD5List.ConfigFilePath + AssetBundleController.GetPlatformName(target) + '/' + CampareMD5ToGenerateVersionNum.FileName; string SavePath = BundleConfigManager.SavePath + AssetBundleController.GetPlatformName(target) + "/VersionNum/"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } SavePath += "VersionNum.assetbundle"; Object obj = AssetDatabase.LoadMainAssetAtPath(assetPath); BuildPipeline.BuildAssetBundle(obj, null, SavePath, _option, target); AssetDatabase.Refresh(); }
private static bool LoadThumbs(ref object __result, ref string assetName, AssetBundleController __instance) { if (__instance.assetBundleName.Contains("thumnbnail/thumbnail_") || __instance.assetBundleName.Contains("thumnbnail/thumnbs_")) { if (thumbAbdata.TryGetValue(assetName, out var modAbdataDir)) { var path = BepInEx.Utility.CombinePaths(modAbdataDir, "thumnbnail_R", assetName + ".png"); if (File.Exists(path)) { Log.Debug($"Loading thumbnail ({path})"); __result = LoadPNG(path); return(false); } } } return(true); }
public static void ExecuteAll(UnityEditor.BuildTarget target, string name) { //清空一下缓存 Caching.CleanCache(); string SavePath = AssetBundleController.GetPlatformPath(target); if (SavePath.Length != 0) { Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); string exportPate = SavePath + name + ".assetbundle"; BuildPipeline.BuildAssetBundle(null, SelectedAsset, exportPate, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, target); } AssetDatabase.Refresh(); }
void OnGUI() { if (GUI.Button(new Rect(40f, 20f, 200f, 50f), "创建assetbundle散包")) { CreateAssetBundle.Execute(buildTarget); EditorUtility.DisplayDialog("", "创建assetbundle散包", "OK"); } if (GUI.Button(new Rect(40f, 90f, 200f, 50f), "创建assetbundle整包")) { string filename = EditorUtility.SaveFilePanel("", AssetBundleController.GetPlatformPath(buildTarget), "输入bundle名称,点击保存", "assetbundle"); CreateAssetBundle.ExecuteAll(filename, buildTarget); EditorUtility.DisplayDialog("", filename, "OK"); } if (GUI.Button(new Rect(300f, 20f, 200f, 50f), "一键所有prefab散包")) { VisualAutuPack.Execute(buildTarget); //CreateAssetBundle.Execute(buildTarget); //EditorUtility.DisplayDialog("", "创建assetbundle散包", "OK"); } if (GUI.Button(new Rect(300f, 90f, 200f, 50f), "删除动作组件")) { bool isOk = EditorUtility.DisplayDialog("删除动作组件", "警告:不可逆过程,需要通过svn才能还原!确定要删除所有动作组件吗", "确定", "取消"); if (isOk) { VisualAutuPack.DelAnimationComponent(); } } if (GUI.Button(new Rect(300f, 160f, 200f, 50f), "一键所有动作组件bundle")) { VisualAutuPack.ExecuteAnim(buildTarget); } if (GUI.Button(new Rect(40f, 160f, 200f, 50f), "资源加密")) { CreateAssetBundle.ExecuteEncryption(buildTarget); } if (GUI.Button(new Rect(40f, 230f, 200f, 50f), "生成 MD5")) { CreateMD5List.Execute(buildTarget); EditorUtility.DisplayDialog("", "MD5 生成OK", "OK"); } }
/// <summary> /// assetbundle打包 /// </summary> /// <param name="target">目标平台</param> public static void Execute(UnityEditor.BuildTarget target) { BundleConfigManager.ReadConfig(); Dictionary <string, List <string> > bundles = BundleConfigManager.Bundles; string savePath = BundleConfigManager.SavePath + AssetBundleController.GetPlatformName(target) + '/'; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } if (bundles.Count <= 0) { Debug.LogError(BundleConfigManager.ConfigFileName + " is empty."); return; } //打包 foreach (KeyValuePair <string, List <string> > bundle in bundles) { List <Object> objs = new List <Object>(); foreach (string path in bundle.Value) { FillObjToList(path, objs); } BuildPipeline.BuildAssetBundle(objs[0], objs.ToArray(), savePath + bundle.Key + ".assetbundle", _option, target); } //计算MD5 CreateMD5List.Execute(target); //比较MD5 CampareMD5ToGenerateVersionNum.Execute(target); //修改Version文件 CreateAssetBundleForXmlVersion.Execute(target); // scene目录下的资源 AssetDatabase.Refresh(); }
private static Texture2D LoadAsset(AssetBundleController abc, string assetName) { if (abc.assetBundleName.Contains("thumnbnail/thumbnail_") || abc.assetBundleName.Contains("thumnbnail/thumnbs_")) { if (MoreSlotID.ThumbList.TryGetValue(assetName, out string abdataDir)) { string text = BepInEx.Utility.CombinePaths(abdataDir, "thumnbnail_R", assetName + ".png"); if (File.Exists(text)) { Console.WriteLine("Load thumb: " + text); return(LoadPNG(text)); } else { Console.WriteLine($"Thumbnail '{text}' does not exist"); } } } return(abc.LoadAsset <Texture2D>(assetName)); }
public static void ExecuteScene(UnityEditor.BuildTarget target) { //清空一下缓存 Caching.CleanCache(); string SavePath = AssetBundleController.GetPlatformPath(target); string exportPath = SavePath + "Scene/"; if (Directory.Exists(exportPath) == false) { Directory.CreateDirectory(exportPath); } string currentScene = EditorApplication.currentScene; string currentSceneName = currentScene.Substring(currentScene.LastIndexOf('/') + 1, currentScene.LastIndexOf('.') - currentScene.LastIndexOf('/') - 1); string fileName = exportPath + currentSceneName + ".unity3d"; BuildPipeline.BuildStreamedSceneAssetBundle(new string[1] { EditorApplication.currentScene }, fileName, target); AssetDatabase.Refresh(); }
public static void Execute(UnityEditor.BuildTarget target) { // if (AssetBundleController.CheckPlatform(target) == false) // return; string SavePath = AssetBundleController.GetPlatformPath(target); // 当前选中的资源列表 foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { string path = AssetDatabase.GetAssetPath(o); // 过滤掉meta文件和文件夹 if (path.Contains(".meta") || path.Contains(".") == false) { continue; } // 过滤掉UIAtlas目录下的贴图和材质(UI/Common目录下的所有资源都是UIAtlas) if (path.Contains("UI/Common")) { if ((o is Texture) || (o is Material)) { continue; } } path = SavePath + o.name; //path = path.Substring(SavePath.Length, path.Length - path.LastIndexOf('.') - 1); path += ".assetbundle"; BuildPipeline.BuildAssetBundle(o, null, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, target); } AssetDatabase.Refresh(); }
public static bool CreateData_PrefabData_Patch(ref CustomSelectSet __result, ref AccessoryData item, ref Rect smallRect, ref AssetBundleController abc) { Vector2 vector = new Vector2(256f, 256f); Texture2D texture = LoadAsset(abc, item.prefab_F); Sprite thumbnail_L = Sprite.Create(texture, new Rect(Vector2.zero, vector), vector * 0.5f, 100f, 0u, SpriteMeshType.FullRect); Sprite thumbnail_S = Sprite.Create(texture, smallRect, smallRect.size * 0.5f, 100f, 0u, SpriteMeshType.FullRect); __result = new CustomSelectSet(item.id, item.name_LineFeed, thumbnail_S, thumbnail_L, item.isNew); return(false); }
private static bool SetupSearchPrefix(object __instance, ref object datas, ref string search) { string text = string.Empty; int num = search.LastIndexOf("/"); if (num != -1) { text = search.Substring(0, num); search = search.Remove(0, num + 1); } string[] files = Directory.GetFiles(GlobalData.assetBundlePath + "/" + text, search, SearchOption.TopDirectoryOnly); Array.Sort(files); foreach (string path in files) { if (Path.GetExtension(path).Length == 0) { string text2 = Path.GetFileNameWithoutExtension(path); if (text.Length > 0) { text2 = text + "/" + text2; } AssetBundleController assetBundleController = new AssetBundleController(); assetBundleController.OpenFromFile(GlobalData.assetBundlePath, text2); var args = new Type[] { datas.GetType(), typeof(AssetBundleController) }; Traverse.Create(__instance).Method("Setup", args).GetValue(datas, assetBundleController); assetBundleController.Close(false); } } if (Directory.Exists(MoreSlotID.ModFolder)) { foreach (var modDir in Directory.GetDirectories(MoreSlotID.ModFolder, "*", SearchOption.TopDirectoryOnly)) { var abdataDir = Path.Combine(modDir, "abdata"); var listDir = BepInEx.Utility.CombinePaths(abdataDir, "list", text); if (Directory.Exists(listDir)) { foreach (string list in Directory.GetFiles(listDir, search + "_Mlist.txt")) { Console.WriteLine("Load Mlist: " + list); StreamReader streamReader = new StreamReader(new FileStream(list, FileMode.Open)); string assetBundleName = streamReader.ReadLine(); MoreSlotID.AssetList[assetBundleName] = abdataDir; string contents = streamReader.ReadToEnd(); string tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, contents); CustomDataListLoader customDataListLoader = new CustomDataListLoader(); customDataListLoader.Load(tempFileName); File.Delete(tempFileName); foreach (var data in Traverse.Create(customDataListLoader).Field("datas").GetValue <List <string[]> >()) { MoreSlotID.ThumbList[data[data.Length - 1]] = abdataDir; } AssetBundleController assetBundleController2 = new AssetBundleController(); assetBundleController2.OpenFromFile(abdataDir, assetBundleName); var args = new Type[] { datas.GetType(), typeof(AssetBundleController), typeof(CustomDataListLoader) }; Traverse.Create(__instance).Field("action").Method("Invoke", args).GetValue(datas, assetBundleController2, customDataListLoader); assetBundleController2.Close(false); } } } } return(false); }
public static void ExecuteEncryption(UnityEditor.BuildTarget target) { //清空一下缓存 Caching.CleanCache(); string platfrom = AssetBundleController.GetPlatformName(target); string dir = System.IO.Path.Combine(Application.dataPath, "StreamingAssets/AssetBundle/" + platfrom); foreach (string filePath in Directory.GetFiles(dir)) { if (filePath.Contains(".meta") || filePath.Contains("VersionMD5") || filePath.Contains(".xml") || filePath.Contains(".enc") || filePath.Contains(".lua")) { continue; } string key = filePath.Substring(dir.Length + 1, filePath.Length - dir.Length - 1); FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); byte[] fileData = new byte[file.Length]; byte[] NewHeader = System.Text.Encoding.UTF8.GetBytes("DreamfactionGame"); byte[] NewEnd = System.Text.Encoding.UTF8.GetBytes("zmy"); byte[] buff = new byte[(int)file.Length + NewHeader.Length + NewEnd.Length]; file.Read(fileData, 0, (int)file.Length); //对二进制文件添加固定头尾,中端修改内容 for (int i = 0; i < buff.Length; i++) { if (i >= 0 && i < NewHeader.Length) { buff[i] = NewHeader[i]; //buff[i] += (byte)i; } else if (i >= NewHeader.Length && i < fileData.Length + NewHeader.Length) { buff[i] = fileData[i - NewHeader.Length]; buff[i] += 1; } else if (i >= fileData.Length + NewHeader.Length && i < buff.Length) { int randomNum = Random.Range(97, 123); buff[i] = (byte)randomNum; } } file.Flush(); file.Close(); fileData = null; if (File.Exists(filePath)) { File.Delete(filePath); } key = key.Substring(0, key.LastIndexOf('.')); key += ".enc"; string newFilePath = filePath.Substring(0, filePath.LastIndexOf('.')); newFilePath += ".enc"; if (File.Exists(newFilePath)) { // string nMessage = key + "资源有重名,是否覆盖"; // if (EditorUtility.DisplayDialog("", nMessage, "是", "否") == false) // { // EditorUtility.DisplayDialog("", "资源加密已取消,请修改资源名称重新打包", "OK"); // return; // } // else // { // File.Delete(key); // } File.Delete(key); } FileStream stream = new FileStream(dir + "/" + key, FileMode.Create); stream.Write(buff, 0, buff.Length); stream.Flush(); stream.Close(); buff = null; } AssetDatabase.Refresh(); EditorUtility.DisplayDialog("", "资源加密完成", "OK"); }
public void Awake() { st = new AssetBundleController(); loaded = false; }