/// <summary> /// </summary> public static void MakeArtResAssetBundleNames() { string baseBunldDir = AppSetting.BundleArtResDir; string[] folders = AppSetting.BundleArtResFolders; foreach (string fold in folders) { foreach (string filepath in Directory.GetFiles(baseBunldDir + fold, "*.*", SearchOption.AllDirectories)) { if (filepath.EndsWith(".meta")) { continue; } var importer = AssetImporter.GetAtPath(filepath); if (importer == null) { ToolsHelper.Error(string.Format("Not found: {0}", filepath)); continue; } string bundleName = filepath.Substring(baseBunldDir.Length); bundleName = bundleName.Replace("\\", "/").ToLower(); importer.assetBundleName = bundleName + AppSetting.ExtName; } } }
public static bool IsPlaying() { if (EditorApplication.isPlaying) { ToolsHelper.Error("请先停止运行"); EditorUtility.DisplayDialog("提示", "请先停止运行","知道了..."); return true; } return false; }
public static void OpenLastScene() { var lastScene = EditorPrefs.GetString(LastScenePrefKey); if (!string.IsNullOrEmpty(lastScene)) { ToolsHelper.OpenScene(lastScene); } else { ToolsHelper.Error("Not found last scene!"); } }
/// <summary> /// 删除硬链接目录 /// </summary> /// <param name="linkPath"></param> public static void DeleteLink(string linkPath) { var os = Environment.OSVersion; if (os.ToString().Contains("Windows")) { ToolsHelper.ExecuteCommand(String.Format("rmdir \"{0}\"", linkPath)); } else if (os.ToString().Contains("Unix")) { ToolsHelper.ExecuteCommand(String.Format("rm -Rf \"{0}\"", linkPath)); } else { ToolsHelper.Error(String.Format("[SymbolLinkFolder]Error on OS: {0}", os.ToString())); } }
/// <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 SymbolLinkFolder(string srcFolderPath, string targetPath) { var os = Environment.OSVersion; if (os.ToString().Contains("Windows")) { ToolsHelper.ExecuteCommand(String.Format("mklink /J \"{0}\" \"{1}\"", targetPath, srcFolderPath)); } else if (os.ToString().Contains("Unix")) { var fullPath = Path.GetFullPath(targetPath); if (fullPath.EndsWith("/")) { fullPath = fullPath.Substring(0, fullPath.Length - 1); fullPath = Path.GetDirectoryName(fullPath); } ToolsHelper.ExecuteCommand(String.Format("ln -s {0} {1}", Path.GetFullPath(srcFolderPath), fullPath)); } else { ToolsHelper.Error(String.Format("[SymbolLinkFolder]Error on OS: {0}", os.ToString())); } }
/// <summary> /// 打开外部程序 /// </summary> /// <param name="_exePathName">EXE所在绝对路径及名称带.exe</param> /// <param name="_exeArgus">启动参数</param> public static void OpenEXE(string filePath, string _exeArgus = null) { try { FileInfo file = new FileInfo(filePath); if (!file.Exists) { ToolsHelper.Error("文件不存在:"+ file.FullName); return; } Process myprocess = new Process(); //ProcessStartInfo startInfo = new ProcessStartInfo(file.FullName, _exeArgus); myprocess.StartInfo.FileName = file.FullName; myprocess.StartInfo.WorkingDirectory = file.DirectoryName; myprocess.StartInfo.UseShellExecute = false; myprocess.StartInfo.CreateNoWindow = true; myprocess.Start(); } catch (Exception ex) { ToolsHelper.Error("出错原因:" + ex.Message); } }
/// <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(); } }