ModelTranslator: 菜单转换取消时用 taskkill 杀进程树,python -u 实时输出

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ud18010
2026-07-15 19:55:20 +08:00
co-authored by Claude Opus 4.8
parent 3a17c96220
commit 18b40d1f67
+11 -2
View File
@@ -60,6 +60,8 @@ namespace XGame.Editor
{
EditorApplication.update -= OnUpdate;
SavePrefs();
if (_proc != null)
UnityEngine.Debug.LogWarning("[模型转换] 窗口关闭或脚本重编译中止了正在进行的转换");
KillProc();
}
@@ -177,7 +179,7 @@ namespace XGame.Editor
{
FileName = _pythonPath,
Arguments = string.Format(
"\"{0}\" \"{1}\" -o \"{2}\" --max-size {3} --blender \"{4}\"",
"-u \"{0}\" \"{1}\" -o \"{2}\" --max-size {3} --blender \"{4}\"",
script, _fbxPath, Path.Combine(RepoRoot, outRel), _maxSize, _blenderPath),
WorkingDirectory = RepoRoot,
UseShellExecute = false,
@@ -267,10 +269,17 @@ namespace XGame.Editor
private void KillProc()
{
if (_proc == null) return;
try { if (!_proc.HasExited) _proc.Kill(); }
try
{
// 用 taskkill /T 连 blender 子进程一起杀(Mono BCL 无 Kill(tree) 重载)
if (!_proc.HasExited)
Process.Start(new ProcessStartInfo("taskkill", "/PID " + _proc.Id + " /T /F")
{ UseShellExecute = false, CreateNoWindow = true });
}
catch { /* 进程可能刚好退出 */ }
_proc.Dispose();
_proc = null;
lock (_lock) _pending.Clear(); // 丢弃残留输出,避免插在 [已取消] 之后
}
}
}