chore(Git): 添加Unity拉取最新版本的快捷编辑器工具

This commit is contained in:
2025-10-23 15:56:42 +08:00
parent f6f523e609
commit bfb5072da0
2 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
using UnityEditor;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace Editor
{
public static class GitPullEditor
{
static bool isRunning = false;
// 菜单项
[MenuItem("Tools/Git/拉取最新版本", false, 100)]
public static void PullLatest()
{
if (isRunning)
{
EditorUtility.DisplayDialog("Git 拉取", "正在拉取中,请稍候...", "确定");
return;
}
isRunning = true;
var projectRoot = Directory.GetParent(Application.dataPath).FullName;
var psi = new ProcessStartInfo
{
FileName = "git",
Arguments = "pull",
WorkingDirectory = projectRoot,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8
};
var proc = new Process { StartInfo = psi, EnableRaisingEvents = true };
var output = new StringBuilder();
proc.OutputDataReceived += (s, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
output.AppendLine(e.Data);
UnityEngine.Debug.Log("[git] " + e.Data);
}
};
proc.ErrorDataReceived += (s, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
output.AppendLine(e.Data);
UnityEngine.Debug.LogError("[git] " + e.Data);
}
};
try
{
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
// 等待完成(超时 10 分钟)
proc.WaitForExit(600000);
isRunning = false;
if (proc.ExitCode == 0)
{
EditorUtility.DisplayDialog("Git 拉取", "拉取完成。请查看控制台获取详细信息。", "确定");
}
else
{
EditorUtility.DisplayDialog("Git 拉取失败", $"ExitCode: {proc.ExitCode}\n请查看控制台输出。", "确定");
}
}
catch (System.Exception ex)
{
isRunning = false;
UnityEngine.Debug.LogException(ex);
EditorUtility.DisplayDialog("Git 拉取异常", ex.Message, "确定");
}
}
// 菜单验证,拉取中禁用该菜单项
[MenuItem("Tools/Git/拉取最新版本", true)]
public static bool ValidatePullLatest()
{
return !isRunning;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 10b461d8a5754bfc8596240a17155757
timeCreated: 1761206120