2024-10-08 15:19:05 +00:00
|
|
|
|
|
2024-10-23 17:30:59 +00:00
|
|
|
|
#if UNITY_EDITOR
|
2024-10-08 15:19:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace UguiToolkit.Editor
|
|
|
|
|
{
|
|
|
|
|
public static class CommandHelper
|
|
|
|
|
{
|
2024-10-29 17:51:06 +00:00
|
|
|
|
public static RotScaleJsonData CalcRotScale(in string srcImgDirPath, in string targetImgDirPath)
|
2024-10-08 15:19:05 +00:00
|
|
|
|
{
|
|
|
|
|
var rotScaleInfoFilePath = Path.GetFullPath(EditorConst.RotScaleInfoFilePath);
|
|
|
|
|
var rotScaleInfoToolFilePath = Path.GetFullPath(EditorConst.RotScaleInfoToolFilePath);
|
|
|
|
|
if (File.Exists(rotScaleInfoFilePath)) File.Delete(rotScaleInfoFilePath);
|
|
|
|
|
|
|
|
|
|
RunCmd(string.Format("{0} -src {1} -target {2} -distance_difference 0.06 -output_path {3}",
|
|
|
|
|
rotScaleInfoToolFilePath,
|
|
|
|
|
Path.GetFullPath(srcImgDirPath),
|
|
|
|
|
Path.GetFullPath(targetImgDirPath),
|
|
|
|
|
Path.GetFullPath(rotScaleInfoFilePath)));
|
|
|
|
|
if (!File.Exists(rotScaleInfoFilePath))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError($"[E] 文件{rotScaleInfoFilePath} 未能正确获得");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (StreamReader reader = File.OpenText(rotScaleInfoFilePath))
|
|
|
|
|
{
|
|
|
|
|
var jsonData = reader.ReadToEnd();
|
|
|
|
|
RotScaleJsonData rotScaleJsonData = JsonConvert.DeserializeObject<RotScaleJsonData>(jsonData);
|
|
|
|
|
return rotScaleJsonData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行 cmd 命令
|
|
|
|
|
public static void RunCmd(in string cmd)
|
|
|
|
|
{
|
|
|
|
|
var p = new System.Diagnostics.Process();
|
|
|
|
|
p.StartInfo.FileName = "cmd.exe";
|
|
|
|
|
p.StartInfo.Arguments = "/c " + cmd; // 使用 /c 参数执行命令并关闭 cmd 窗口
|
|
|
|
|
p.StartInfo.UseShellExecute = false;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
p.StartInfo.CreateNoWindow = true;
|
2024-10-08 15:19:05 +00:00
|
|
|
|
p.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
p.StartInfo.RedirectStandardError = true;
|
|
|
|
|
|
|
|
|
|
p.Start();
|
|
|
|
|
var output = p.StandardOutput.ReadToEnd();
|
|
|
|
|
var error = p.StandardError.ReadToEnd();
|
|
|
|
|
p.WaitForExit();
|
|
|
|
|
|
|
|
|
|
Debug.Log("cmd output : " + output);
|
|
|
|
|
Debug.Log("cmd error : " + error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 17:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|