/// <summary> /// 添加UI预设上Text字体为空的字体-黑体SIMHEI /// </summary> public static void SetUIPrefabTextFont() { Font font = AssetDatabase.LoadAssetAtPath <Font>("Assets/Resources/Font/SIMHEI.TTF"); List <string> FileName = FindUIPrefab(); string BasePath = "Assets/GameRes/BundleRes/UI/"; ToolsHelper.Log("font:" + font, false); foreach (var file in FileName) { //ToolsHelper.Log("file:" + file, false); GameObject go = AssetDatabase.LoadAssetAtPath(BasePath + file, typeof(GameObject)) as GameObject; Text[] texts = go.GetComponentsInChildren <Text>(true); foreach (var item in texts) { if (item.font == null) { item.font = font; //ToolsHelper.Log("Text:" + item.name, false); } } EditorUtility.SetDirty(go); AssetDatabase.SaveAssets(); } }
/// <summary> /// 生成AB资源文件列表 /// </summary> public static void CreateAssetBundleFileInfo() { string abRootPath = GetExportPath(); string abFilesPath = abRootPath + AppSetting.ABFiles; if (File.Exists(abFilesPath)) { File.Delete(abFilesPath); } var abFileList = new List <string>(Directory.GetFiles(abRootPath, "*" + AppSetting.ExtName, SearchOption.AllDirectories)); abFileList.Add(abRootPath + AppSetting.MineGameName); FileStream fs = new FileStream(abFilesPath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2018, 1, 1)); int ver = ((int)((DateTime.Now - startTime).TotalMinutes)); sw.WriteLine(ver + "|" + DateTime.Now.ToString("u")); for (int i = 0; i < abFileList.Count; i++) { string file = abFileList[i]; long size = 0; string md5 = MD5Utils.MD5File(file, out size); string value = file.Replace(abRootPath, string.Empty).Replace("\\", "/"); sw.WriteLine(value + "|" + md5 + "|" + size); } sw.Close(); fs.Close(); ToolsHelper.Log("资源版本Version:" + ver + " 已复制到剪切板"); ToolsHelper.Log("ABFiles文件生成完成"); ToolsHelper.CopyString(ver.ToString()); }
static void CreateTextLang(MenuCommand menuCommadn) { GameObject parent = menuCommadn.context as GameObject; if (parent != null && parent.GetComponentInParent <Canvas>() != null) { GameObject go = new GameObject("New Lang Text"); GameObjectUtility.SetParentAndAlign(go, parent); go.AddComponent <UILangText>(); Text txt = go.AddComponent <Text>(); RectTransform rect = go.GetComponent <RectTransform>(); rect.sizeDelta = new Vector2(200, 22); txt.alignment = TextAnchor.MiddleLeft; txt.fontSize = 22; Color outColor = Color.white; ColorUtility.TryParseHtmlString("#FFFFFF", out outColor); txt.color = outColor; txt.text = "New Lang Text"; txt.resizeTextForBestFit = true; txt.supportRichText = true; Font font = AssetDatabase.LoadAssetAtPath <Font>("Assets/Resources/Font/SIMHEI.TTF"); txt.font = font; } else { ToolsHelper.Log("只能在UI下创建LangText"); } }
static void CreateVideoButtonLang(MenuCommand menuCommadn) { GameObject parent = menuCommadn.context as GameObject; if (parent != null && parent.GetComponentInParent <Canvas>() != null) { GameObject goBtn = new GameObject("New Button"); GameObjectUtility.SetParentAndAlign(goBtn, parent); Image image = goBtn.AddComponent <Image>(); image.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/GameRes/ArtRes/UIAtlas/PublicButton/Btn1_BG.png"); image.SetNativeSize(); GameObject BtnIcon = new GameObject("Icon"); BtnIcon.transform.SetParent(goBtn.transform, false); Image IconImg = BtnIcon.AddComponent <Image>(); IconImg.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/GameRes/ArtRes/UIAtlas/PublicButton/Btn1_1.png"); RectTransform IconImgrect = IconImg.GetComponent <RectTransform>(); IconImgrect.anchorMin = Vector2.zero; IconImgrect.anchorMax = Vector2.one; IconImgrect.offsetMin = Vector2.zero; IconImgrect.offsetMax = Vector2.zero; IconImgrect.sizeDelta = new Vector2(-16, -16); DBTVideoBtn btn = goBtn.AddComponent <DBTVideoBtn>(); btn.image = IconImg; GameObject goTxt = new GameObject("Text"); GameObjectUtility.SetParentAndAlign(goTxt, goBtn); goTxt.AddComponent <UILangText>(); Text txt = goTxt.AddComponent <Text>(); Color color = Color.black; ColorUtility.TryParseHtmlString("#FFFFFF", out color); txt.color = color; RectTransform rect = goTxt.GetComponent <RectTransform>(); rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.offsetMin = Vector2.zero; rect.offsetMax = Vector2.zero; rect.sizeDelta = new Vector2(-40, -34); txt.fontSize = 24; txt.alignment = TextAnchor.MiddleCenter; txt.text = "Lang Button"; //txt.resizeTextForBestFit = true; //txt.supportRichText = true; Font font = AssetDatabase.LoadAssetAtPath <Font>("Assets/Resources/Font/SIMHEI.TTF"); txt.font = font; Shadow shadow = goTxt.AddComponent <Shadow>(); shadow.effectColor = new Color(0, 0, 0, 1); shadow.effectDistance = new Vector2(1, -3); } else { ToolsHelper.Log("只能在UI下创建LangText"); } }
public static void IOS_ReleaseApp() { if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS) { ToolsHelper.Log($"平台选择错误,目前平台不是iOS,是{EditorUserBuildSettings.activeBuildTarget}"); return; } BuildAPKTools.ModifyBuildSettingsScene(); BuildAPKTools.BulidTarget(EPlatformType.SDK_ReleaseIOS); BuildAPKTools.ReductionBuildSettingsScene(); }
public static void CreateVersionPackageApp() { if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android) { ToolsHelper.Log($"平台选择错误,目前平台不是Android,是{EditorUserBuildSettings.activeBuildTarget}"); return; } BuildAPKTools.ModifyBuildSettingsScene(); BuildAPKTools.BulidTarget(EPlatformType.VersionPackage); BuildAPKTools.ReductionBuildSettingsScene(); }
/// <summary> /// 重新打包资源 /// </summary> /// <returns></returns> public static void ReBuildAllAssetBundles() { if (ToolsHelper.IsPlaying()) { return; } ToolsHelper.ClearConsole(); string outputPath = GetExportPath(); Directory.Delete(outputPath, true); ToolsHelper.Log("删除目录: " + outputPath); BuildAllAssetBundles(); }
/// <summary> /// 清理冗余,即无此资源,却有AssetBundle的 /// </summary> public static void CleanAssetBundlesRedundancies() { var platformName = AppSetting.PlatformName; var outputPath = GetExportPath(); int count = 0; var toList = new List <string>(Directory.GetFiles(outputPath, "*.*", SearchOption.AllDirectories)); for (var i = toList.Count - 1; i >= 0; i--) { var filePath = toList[i]; var abName = toList[i].Replace(outputPath, "").Replace('\\', '/'); var extName = Path.GetExtension(filePath); if (abName != platformName && extName != ".manifest") { //删除.meta文件 if (extName == ".meta") { File.Delete(filePath); } else { if (AssetDatabase.GetAssetPathsFromAssetBundle(abName).Length == 0) { var manifestPath = filePath + ".manifest"; File.Delete(filePath); ToolsHelper.Log("Delete... " + filePath); count += 1; if (File.Exists(manifestPath)) { File.Delete(manifestPath); ToolsHelper.Log("Delete... " + manifestPath); count += 1; } } } } //删除空文件夹 DirectoryInfo dir = new DirectoryInfo(outputPath); DirectoryInfo[] subdirs = dir.GetDirectories("*.*", SearchOption.AllDirectories); foreach (DirectoryInfo subdir in subdirs) { FileInfo[] subFiles = subdir.GetFiles(); if (subFiles.Length == 0) { subdir.Delete(); } } } ToolsHelper.Log("清理冗余文件完成!! 共" + count + "个文件!"); }
static IEnumerator _OnBuildAllAssetBundles() { Stopwatch watch = new Stopwatch(); watch.Start(); yield return(new WaitForSeconds(0.3f)); //CopyHotFix(); CreateLayerCollisionMatrix(); yield return(null); RemoveAssetBundleNames(); MakeAssetBundleNames(); yield return(null); //RemoveUIPrefabTextFont(); yield return(new WaitForSeconds(0.1f)); ToolsHelper.Log("资源打包中..."); yield return(null); var outputPath = GetExportPath(); ToolsHelper.Log("打包路径..." + outputPath); #if UNITY_ANDROID _SetAtlasIncludeInBuild(false); #endif yield return(new WaitForSeconds(0.5f));//DessterministicAssetBundle ToolsHelper.Log("设置图集属性完成..."); BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); yield return(new WaitForSeconds(0.5f)); //_SetAtlasIncludeInBuild(true); #if UNITY_ANDROID CopyOnceAuido(); #endif yield return(null); CreateAssetBundleFileInfo(); yield return(null); //SetUIPrefabTextFont(); yield return(new WaitForSeconds(0.1f)); watch.Stop(); ToolsHelper.Log("资源打包完成!!用时:" + (watch.ElapsedMilliseconds / 1000.0f) + "秒"); AssetDatabase.Refresh(); yield break; }
public static void ClearPCPersistentData() { string DataPath = Application.dataPath; string userPathBas = DataPath.Substring(0, DataPath.LastIndexOf("/") + 1); userPathBas = Path.Combine(userPathBas, "LocalFile"); if (Directory.Exists(userPathBas)) { foreach (string dir in Directory.GetDirectories(userPathBas)) { Directory.Delete(dir, true); } ToolsHelper.Log("删除PersistentData完成!"); } }
/// <summary> /// 复制音频 /// </summary> public static void CopyOnceAuido() { BuildTarget platfrom = EditorUserBuildSettings.activeBuildTarget; if (platfrom != BuildTarget.Android) { return; } string sourcePath = AppSetting.DataPath + "GameRes/BundleRes/Audio/Once"; string targetPath = GetExportPath() + "audio/once"; ToolsHelper.Log("音效源目录: " + sourcePath); ToolsHelper.Log("targetPath: " + targetPath); //找到目录下所有音频文件 DirectoryInfo folder = new DirectoryInfo(sourcePath); List <string> AuiodFile = new List <string>(); foreach (var file in folder.GetFiles()) { if (file.FullName.EndsWith(".meta")) { continue; } AuiodFile.Add(file.Name); } //foreach (var item in AuiodFile) //{ // ToolsHelper.Log(item); //} foreach (var item in AuiodFile) { string FileSourcePath = Path.Combine(sourcePath, item); string FileTargetPathPath = Path.Combine(targetPath, item); if (File.Exists(FileTargetPathPath)) { continue; } //ToolsHelper.Log() File.Copy(FileSourcePath, FileTargetPathPath); } ToolsHelper.Log("音频文件复制完成"); }
/// <summary> /// Unity 5新AssetBundle系统,需要为打包的AssetBundle配置名称 /// GameRes/BundleRes目录整个自动配置名称,因为这个目录本来就是整个导出 /// </summary> public static void MakeAssetBundleNames() { string baseBunldDir = AppSetting.BundleResDir; // 设置新的资源名 foreach (string filepath in Directory.GetFiles(baseBunldDir, "*.*", SearchOption.AllDirectories)) { if (filepath.EndsWith(".meta")) { continue; } var importer = AssetImporter.GetAtPath(filepath); if (importer == null) { ToolsHelper.Error(string.Format("Not found: {0}", filepath)); continue; } // var bundleName = filepath.Substring(baseBunldDir.Length, filepath.Length - baseBunldDir.Length); string bundleName = filepath.Substring(baseBunldDir.Length); bundleName = bundleName.Replace("\\", "/").ToLower(); if (bundleName.StartsWith(AppSetting.ConfigBundleDir.ToLower())) //config全部打到一个文件夹中 { bundleName = StringTools.SubstringIndexOf(bundleName, '/', 1); } //bundleName = bundleName.Replace("\\", "/").ToLower(); //if (bundleName.StartsWith("lua/")) //{ // bundleName = StringUtil.SubstringIndexOf(bundleName, '/', AppSetting.LuaAssetBundleDepth); //} importer.assetBundleName = bundleName + AppSetting.ExtName; } //setAtlasIncludeInBuild(true); //setUIAtlasPropert(); //设置UIAtlas MakeArtResAssetBundleNames(); ToolsHelper.Log("设置全部资源AssetBundle名称完成!"); }
public static void RemoveAssetBundleNames() { List <string> filterDir = new List <string>(); filterDir.Add(AppSetting.BundleResDir); foreach (string fold in AppSetting.BundleArtResFolders) { filterDir.Add(AppSetting.BundleArtResDir + fold); } bool isClena = false; foreach (string assetGuid in AssetDatabase.FindAssets("")) { string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid); AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath); string bundleName = assetImporter.assetBundleName; if (string.IsNullOrEmpty(bundleName)) { continue; } isClena = true; foreach (string filter in filterDir) { if (assetPath.StartsWith(filter)) //清除非打包资源目录下的资源名 { isClena = false; break; } } if (isClena) { assetImporter.assetBundleName = null; } } ToolsHelper.Log("全部非打包资源AssetBundle名称已清除!"); }
static void CreateUIScript(MenuCommand menuCommadn) { GameObject target = menuCommadn.context as GameObject; if (target != null && target.transform.parent.name == "UICanvas" && target.name.EndsWith("UI")) { if (target.name.StartsWith("New UI")) { ToolsHelper.Log("请修改UI名称!!!"); return; } UIOutlet uiObj = target.GetComponent <UIOutlet>(); if (uiObj != null) { UIScriptExport.ExportUIScript(uiObj); ToolsHelper.Log("生成成功!!!"); AssetDatabase.Refresh(); return; } } ToolsHelper.Log("请选择有效果的UI对象!!!"); }
static void CreateItemScript(MenuCommand menuCommadn) { GameObject target = menuCommadn.context as GameObject; if (target != null && (target.name.EndsWith("Item"))) { UIOutlet uiObj = target.GetComponent <UIOutlet>(); if (uiObj != null) { UIScriptExport.ExportItemScript(uiObj); ToolsHelper.Log("生成成功!!!"); AssetDatabase.Refresh(); return; } } if (target != null && (target.name.EndsWith("ItemP"))) { ToolsHelper.Log("对于ItemP类型的Item,请在对应预设文件夹生成Item"); return; } ToolsHelper.Log("请选择有效果的Item对象!!!,Item包含UIOutlet脚本,并且以Item命名结尾"); }
public static void MkLinkStreamingAssets() { LinkHelper.IsLinkStreamingAssets = !LinkHelper.IsLinkStreamingAssets; LinkHelper.MkLinkStreamingAssets(); ToolsHelper.Log("链接资源到StreamingAssets:" + (LinkHelper.IsLinkStreamingAssets ? "链接" : "关闭")); }
public static void ClearPlayerPrefs() { PlayerPrefs.DeleteAll(); PlayerPrefs.Save(); ToolsHelper.Log("删除缓存(PlayerPrefs)完成!"); }
public static void ToggleSimulationMode() { AssetBundleManager.SimulateAssetBundleInEditor = !AssetBundleManager.SimulateAssetBundleInEditor; ToolsHelper.Log("资源包防真模式:" + (AssetBundleManager.SimulateAssetBundleInEditor ? "开启" : "关闭")); }
/// <summary> /// 执行批处理命令 /// </summary> /// <param name="command"></param> /// <param name="workingDirectory"></param> public static void ExecuteCommand(string command, string workingDirectory = null) { var fProgress = .1f; EditorUtility.DisplayProgressBar("ExecuteCommand", command, fProgress); try { string cmd; string preArg; var os = Environment.OSVersion; //Debug.Log(String.Format("[ExecuteCommand]Command on OS: {0}", os.ToString())); if (os.ToString().Contains("Windows")) { cmd = "cmd.exe"; preArg = "/C "; } else { cmd = "sh"; preArg = "-c "; } ToolsHelper.Log("[ExecuteCommand]" + command); var allOutput = new StringBuilder(); using (var process = new Process()) { if (workingDirectory != null) process.StartInfo.WorkingDirectory = workingDirectory; process.StartInfo.FileName = cmd; process.StartInfo.Arguments = preArg + "\"" + command + "\""; //process.StartInfo.StandardOutputEncoding = Encoding.Default; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; Console.InputEncoding = Encoding.UTF8; process.Start(); while (true) { var line = process.StandardOutput.ReadLine(); if (line == null) break; allOutput.AppendLine(line); EditorUtility.DisplayProgressBar("[ExecuteCommand] " + command, line, fProgress); fProgress += .001f; } var err = process.StandardError.ReadToEnd(); if (!String.IsNullOrEmpty(err)) { ToolsHelper.Error(String.Format("[ExecuteCommand] {0}", err)); } process.WaitForExit(); process.Close(); } if(allOutput.Length>0) ToolsHelper.Log("[ExecuteResult]" + allOutput); } finally { EditorUtility.ClearProgressBar(); } }