public static void ExportExcelProtobuf(ConfigType configType) { string exportPath = PathUtil.GetPath(PathType.DataPath, GetProtobufPath(configType)); string classPath = PathUtil.GetPath(PathType.DataPath, GetClassPath(configType)); string jsonPath = PathUtil.GetPath(PathType.DataPath, GetJsonPath(configType)); List <string> protoNameList = new List <string>(); foreach (string item in Directory.GetFiles(classPath, "*.cs")) { protoNameList.Add(Path.GetFileNameWithoutExtension(item)); } foreach (string item in protoNameList) { string json = FileUtil.GetAsset($"{jsonPath}/{item}.txt").GetString(); object obj; if (configType == ConfigType.Model) { obj = JsonUtil.ToObject(typeof(Manager).Assembly.GetType($"{typeof(Manager).Namespace}.{item}Category"), json); } else { obj = JsonUtil.ToObject(typeof(LccHotfix.Manager).Assembly.GetType($"{typeof(LccHotfix.Manager).Namespace}.{item}Category"), json); } FileUtil.SaveAsset($"{exportPath}/{item}Category.bytes", ProtobufUtil.Serialize(obj)); } }
public static void BuildHotfix() { if (File.Exists("Assets/Hotfix/Unity.Hotfix.asmdef~")) { File.Move("Assets/Hotfix/Unity.Hotfix.asmdef~", "Assets/Hotfix/Unity.Hotfix.asmdef"); LogUtil.Log("安装Hotfix"); AssetDatabase.Refresh(); } else { if (File.Exists("Assets/Hotfix/Unity.Hotfix.asmdef")) { LogUtil.Log("安装Hotfix"); } else { LogUtil.Log("Hotfix丢失"); } } if (File.Exists("Assets/Resources/DLL/Unity.Hotfix.dll.bytes")) { File.Delete("Assets/Resources/DLL/Unity.Hotfix.dll.bytes"); } if (File.Exists("Assets/Resources/DLL/Unity.Hotfix.pdb.bytes")) { File.Delete("Assets/Resources/DLL/Unity.Hotfix.pdb.bytes"); } if (File.Exists("Assets/Bundles/DLL/Unity.Hotfix.dll.bytes")) { File.Delete("Assets/Bundles/DLL/Unity.Hotfix.dll.bytes"); } if (File.Exists("Assets/Bundles/DLL/Unity.Hotfix.pdb.bytes")) { File.Delete("Assets/Bundles/DLL/Unity.Hotfix.pdb.bytes"); } #if Release if (File.Exists("Unity.Hotfix.csproj")) { RoslynUtil.BuildDll("Unity.Hotfix.csproj", "Assets/Resources/DLL/Unity.Hotfix.dll.bytes", BuildType.Release, false); FileUtil.SaveAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", RijndaelUtil.RijndaelEncrypt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FileUtil.GetAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes"))); File.Copy("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", "Assets/Bundles/DLL/Unity.Hotfix.dll.bytes", true); } #else if (File.Exists("Library/ScriptAssemblies/Unity.Hotfix.dll") && File.Exists("Library/ScriptAssemblies/Unity.Hotfix.pdb")) { File.Copy("Library/ScriptAssemblies/Unity.Hotfix.dll", "Assets/Resources/DLL/Unity.Hotfix.dll.bytes", true); File.Copy("Library/ScriptAssemblies/Unity.Hotfix.pdb", "Assets/Resources/DLL/Unity.Hotfix.pdb.bytes", true); FileUtil.SaveAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", RijndaelUtil.RijndaelEncrypt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FileUtil.GetAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes"))); File.Copy("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", "Assets/Bundles/DLL/Unity.Hotfix.dll.bytes", true); File.Copy("Assets/Resources/DLL/Unity.Hotfix.pdb.bytes", "Assets/Bundles/DLL/Unity.Hotfix.pdb.bytes", true); } #endif LinkUtil.BuildLink(); AssetDatabase.Refresh(); }
public static void ExportExcelJson(XSSFWorkbook xssfWorkbook, string name, ConfigType configType) { string exportPath = $"{PathUtil.GetPath(PathType.DataPath, GetJsonPath(configType))}/{Path.GetFileNameWithoutExtension(name)}.txt"; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("{\n\t\"list\" : ["); for (int i = 0; i < xssfWorkbook.NumberOfSheets; i++) { ExportSheetJson(xssfWorkbook.GetSheetAt(i), stringBuilder); } stringBuilder.Append("]\n}"); FileUtil.SaveAsset(exportPath, stringBuilder.ToString()); }
public Object CreateAssetFormTemplate(string pathName, string resourceFile) { //获取要创建资源的绝对路径 string fullName = Path.GetFullPath(pathName); //获取资源的文件名 string fileName = Path.GetFileNameWithoutExtension(pathName); //读取本地模版文件 替换默认的文件名 string content = FileUtil.GetAsset(resourceFile).GetString().Replace(resourceFile.Substring(resourceFile.IndexOf('N'), resourceFile.IndexOf('.') - resourceFile.IndexOf('N')), fileName); //写入新文件 FileUtil.SaveAsset(fullName, content); //刷新本地资源 AssetDatabase.Refresh(); return(AssetDatabase.LoadAssetAtPath(pathName, typeof(Object))); }
public IEnumerator CopyAssets(string[] keys) { foreach (string item in keys) { yield return(StartCoroutine(WebUtil.Download($"{"file:///"}{PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{item}", (byte[] bytes) => { FileUtil.SaveAsset(PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle()), item, bytes); currentCopyCount += 1; Message?.Invoke($"初始化资源 {currentCopyCount} / {copyCount}"); CopyProgress?.Invoke(currentCopyCount, copyCount); }))); } //更新资源 UpdateAssets(string.Empty); }
public Object CreateAssetFormTemplate(string pathName, string resourceFile) { //获取要创建资源的绝对路径 string fullName = Path.GetFullPath(pathName); //获取资源的文件名 string fileName = Path.GetFileNameWithoutExtension(pathName); //读取本地模版文件 替换默认的文件名 string content = FileUtil.GetAsset(resourceFile).GetString().Replace("(Class)", fileName).Replace("(ViewModel)", fileName.Replace("Panel", string.Empty)); //写入新文件 FileUtil.SaveAsset(fullName, content); //刷新本地资源 AssetDatabase.Refresh(); return(AssetDatabase.LoadAssetAtPath(pathName, typeof(Object))); }
public void InitAssets(byte[] bytes) { Message?.Invoke("初始化资源"); FileUtil.SaveAsset(PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle()), "AssetBundleConfig.json", bytes); localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString()); List <string> keyList = new List <string>(); keyList.Add(PathUtil.GetPlatformForAssetBundle()); keyList.Add($"{PathUtil.GetPlatformForAssetBundle()}.manifest"); foreach (string item in localAssetBundleConfig.assetBundleDataDict.Keys) { keyList.Add($"{item}.unity3d"); } copyCount = keyList.Count; //开始拷贝资源 StartCoroutine(CopyAssets(keyList.ToArray())); }
/// <summary> /// 下载资源 /// </summary> /// <param name="url"></param> /// <param name="name"></param> /// <param name="folder"></param> /// <returns></returns> public static IEnumerator Download(string url, string name, params string[] folders) { url = Uri.EscapeUriString(url); UnityWebRequest webRequest = UnityWebRequest.Get(url); yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError || webRequest.isHttpError) { LogUtil.Log(webRequest.error); } else { byte[] bytes = webRequest.downloadHandler.data; FileUtil.SaveAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, folders)}/{name}", bytes); } }
public void BuildCrossBinding() { if (string.IsNullOrEmpty(assets)) { editorWindow.ShowNotification(new GUIContent("请输入程序集")); return; } if (string.IsNullOrEmpty(className)) { editorWindow.ShowNotification(new GUIContent("请输入脚本名")); return; } string path = $"Library/ScriptAssemblies/{assets}.dll"; if (!File.Exists(path)) { editorWindow.ShowNotification(new GUIContent("程序集路径错误")); return; } Type type; if (string.IsNullOrEmpty(namespaceName)) { type = Assembly.LoadFile(path).GetType(className); } else { type = Assembly.LoadFile(path).GetType($"{namespaceName}.{className}"); } if (type == null) { editorWindow.ShowNotification(new GUIContent("没有此脚本")); return; } if (File.Exists($"Assets/Scripts/Runtime/Core/Manager/ILRuntime/Adapter/{className}Adapter.cs")) { File.Delete($"Assets/Scripts/Runtime/Core/Manager/ILRuntime/Adapter/{className}Adapter.cs"); } FileUtil.SaveAsset($"Assets/Scripts/Runtime/Core/Manager/ILRuntime/Adapter/{className}Adapter.cs", CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(type, "LccModel")); AssetDatabase.Refresh(); }
public static void ExportClass(string name, List <Cell> cellList, ConfigType configType) { string exportPath = $"{PathUtil.GetPath(PathType.DataPath, GetClassPath(configType))}/{name}.cs"; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < cellList.Count; i++) { Cell cell = cellList[i]; if (cell.attribute.StartsWith("#")) { continue; } stringBuilder.Append($"\t\t[ProtoMember({i + 1}, IsRequired = true)]\n"); stringBuilder.Append($"\t\tpublic {cell.type} {cell.name} {{ get; set; }}"); if (i != cellList.Count - 1) { stringBuilder.Append("\n"); } } string content = ExcelExportUtil.content.Replace("(LccModel)", $"Lcc{configType}").Replace("(CustomConfig)", name).Replace("(Propertys)", stringBuilder.ToString()); FileUtil.SaveAsset(exportPath, content); }
public static void BuildAssetBundle(AssetBundleSetting assetBundleSetting) { Dictionary <string, AssetBundleData> assetBundleDataDict = new Dictionary <string, AssetBundleData>(); Dictionary <string, AssetBundleRuleType> assetBundleRuleTypeDict = new Dictionary <string, AssetBundleRuleType>(); string path = DirectoryUtil.GetDirectoryPath($"{assetBundleSetting.outputPath}/{GetPlatformForAssetBundle(EditorUserBuildSettings.activeBuildTarget)}"); foreach (DirectoryInfo item in DirectoryUtil.GetDirectorys(new DirectoryInfo(path), new List <DirectoryInfo>())) { item.Delete(); } foreach (FileInfo item in FileUtil.GetFiles(new DirectoryInfo(path), new List <FileInfo>())) { item.Delete(); } List <AssetBundleBuild> assetBundleBuildList = new List <AssetBundleBuild>(); foreach (AssetBundleRule item in assetBundleSetting.assetBundleRuleList) { if (item.assetBundleRuleType == AssetBundleRuleType.File) { FileInfo[] fileInfos = FileUtil.GetFiles(new DirectoryInfo(item.path), new List <FileInfo>()); if (fileInfos.Length == 0) { continue; } List <FileInfo> fileInfoList = (from fileInfo in fileInfos where !string.IsNullOrEmpty(Path.GetExtension(fileInfo.Name)) && Path.GetExtension(fileInfo.Name) != ".meta" select fileInfo).ToList(); foreach (FileInfo fileInfo in fileInfoList) { assetBundleRuleTypeDict.Add(fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets")).Replace("\\", "/"), AssetBundleRuleType.File); } } if (item.assetBundleRuleType == AssetBundleRuleType.Directory) { DirectoryInfo[] directoryInfos = DirectoryUtil.GetDirectorys(new DirectoryInfo(item.path), new List <DirectoryInfo>() { new DirectoryInfo(item.path) }); if (directoryInfos.Length == 0) { continue; } foreach (DirectoryInfo directoryInfo in directoryInfos) { foreach (FileInfo fileInfo in directoryInfo.GetFiles()) { assetBundleRuleTypeDict.Add(fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets")).Replace("\\", "/"), AssetBundleRuleType.Directory); } } } } foreach (AssetBundleData item in assetBundleSetting.assetBundleDataList) { assetBundleBuildList.Add(new AssetBundleBuild() { assetBundleName = item.assetBundleName, assetNames = item.assetNames, }); } AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(path, assetBundleBuildList.ToArray(), BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); foreach (AssetBundleData item in assetBundleSetting.assetBundleDataList) { item.assetBundleHash = assetBundleManifest.GetAssetBundleHash(item.assetBundleName).ToString(); BuildPipeline.GetCRCForAssetBundle($"{path}/{item.assetBundleName}", out item.assetBundleCRC); item.fileSize = FileUtil.GetFileSize($"{path}/{item.assetBundleName}"); assetBundleDataDict.Add(Path.GetFileNameWithoutExtension(item.assetBundleName), item); } AssetBundleConfig assetBundleConfig = new AssetBundleConfig(assetBundleSetting.buildId, assetBundleDataDict, assetBundleRuleTypeDict); FileUtil.SaveAsset(path, "AssetBundleConfig.json", JsonUtil.ToJson(assetBundleConfig)); if (assetBundleSetting.isCopyStreamingAssets) { string copyPath = DirectoryUtil.GetDirectoryPath(PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", GetPlatformForAssetBundle(EditorUserBuildSettings.activeBuildTarget))); foreach (DirectoryInfo item in DirectoryUtil.GetDirectorys(new DirectoryInfo(copyPath), new List <DirectoryInfo>())) { item.Delete(); } foreach (FileInfo item in FileUtil.GetFiles(new DirectoryInfo(copyPath), new List <FileInfo>())) { item.Delete(); } foreach (FileInfo item in FileUtil.GetFiles(new DirectoryInfo(path), new List <FileInfo>())) { if (Path.GetExtension(item.Name) == ".meta") { continue; } File.Copy(item.FullName, $"{PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", GetPlatformForAssetBundle(EditorUserBuildSettings.activeBuildTarget))}/{item.Name}"); } } AssetDatabase.Refresh(); }