33f5ad68bf
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 7m19s
Project CI / AI game creator shell Rust shard 3/4 (push) Successful in 7m26s
Project CI / AI game creator shell Rust shard 4/4 (push) Successful in 7m32s
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 7m34s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m57s
Project CI / AI game creator shell Rust crates (push) Successful in 3m18s
Project CI / Native shell tests (push) Successful in 10m54s
Project CI / Backend tests (push) Successful in 12m42s
Project CI / Frontend tests (push) Successful in 13m4s
Project CI / AI game creator shell web tests (push) Successful in 5m1s
Project CI / Repository checks (push) Successful in 12m48s
AGC 原有插件系统无法直接操作已打开的 Unity Editor。本变更增加内置 `agc-unity-editor`,在 Windows x64 / Unity Mono 上支持当前项目探测、连接与 C# 执行,不向 Unity 工程安装 UPM 桥接包。 ## 主要变更 - 固定复用 DotCraft.Unity 0.4.3 的 Attach 核心,提供自包含 .NET helper,保留上游许可证、来源及修改记录。 - GUI、Runtime、DirectProject 共用 Runner 执行服务;补齐项目身份、并发、总期限、回执确认与持久不确定状态阻断。 - 现有打开项目入口支持 Unity,按项目类型及开关暴露插件和 Agent 工具。 - Windows 构建准备 helper 并随包分发;插件 JS/Rust 测试接入现有 CI 组,Jenkins 增加 .NET 10 工具链预检。 ## 验证 - .NET helper 27 项测试、自包含发布及最小环境协议 smoke 通过。 - Unity 6000.3.7f1 实机验证通过:连接、C# 执行、编译错误修复、断连重连、Domain Reload 后重新握手;真实 Runner 的 ACK、并发拒绝和跨重启阻断通过。 - 宿主 Unity、PluginHost、Cocos、MCP、工具目录与引擎识别定向回归通过;前端类型检查、插件 JS/Rust、CI 配置、格式、编码和文档门禁通过。 Linux CI 不代替 Windows helper/实机验证;发行安装包 UI smoke、其它 Unity 版本和 Unity CoreCLR 未验证。Unity 演示工程中的场景和组件已撤销,不在此 PR 范围内。 --------- Co-authored-by: kdletters <61648117+kdletters@users.noreply.github.com> Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/423
81 lines
4.4 KiB
C#
81 lines
4.4 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
namespace Agc.Unity.Attach;
|
|
|
|
public static class ProjectIdentity
|
|
{
|
|
public static string Normalize(string projectPath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(projectPath) || projectPath.Contains('\0') || !Path.IsPathFullyQualified(projectPath))
|
|
throw new HostException("UnityProjectInvalid", "An absolute Unity project path is required.");
|
|
var supplied = new DirectoryInfo(WithoutDevicePrefix(Path.GetFullPath(projectPath)));
|
|
if (!supplied.Exists || IsLink(supplied))
|
|
throw new HostException("UnityProjectInvalid", "The Unity project root must be an existing ordinary directory.");
|
|
var root = Canonical(projectPath);
|
|
var directory = new DirectoryInfo(root);
|
|
if (!directory.Exists || IsLink(directory))
|
|
throw new HostException("UnityProjectInvalid", "The Unity project root must be an existing ordinary directory.");
|
|
foreach (var child in new[] { "Assets", "Packages", "ProjectSettings" })
|
|
{
|
|
var info = new DirectoryInfo(Path.Combine(root, child));
|
|
if (!info.Exists || IsLink(info))
|
|
throw new HostException("UnityProjectInvalid", "The Unity project directories must be ordinary directories.");
|
|
}
|
|
var version = new FileInfo(Path.Combine(root, "ProjectSettings", "ProjectVersion.txt"));
|
|
if (!version.Exists || IsLink(version))
|
|
throw new HostException("UnityProjectInvalid", "ProjectVersion.txt must be an existing ordinary file.");
|
|
return root;
|
|
}
|
|
|
|
public static bool Same(string? first, string? second)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(first) || string.IsNullOrWhiteSpace(second)) return false;
|
|
try
|
|
{
|
|
return string.Equals(Canonical(first), Canonical(second),
|
|
OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
|
|
}
|
|
catch (Exception error) when (error is ArgumentException or NotSupportedException or IOException or Win32Exception or UnauthorizedAccessException) { return false; }
|
|
}
|
|
|
|
private static bool IsLink(FileSystemInfo info) => (info.Attributes & FileAttributes.ReparsePoint) != 0 || info.LinkTarget != null;
|
|
internal static string Canonical(string path)
|
|
{
|
|
var full = Path.TrimEndingDirectorySeparator(Path.GetFullPath(WithoutDevicePrefix(path)));
|
|
if (OperatingSystem.IsWindows() && Directory.Exists(full))
|
|
{
|
|
// A directory handle resolves 8.3 aliases and junction ancestors to the
|
|
// same physical identity used by Rust canonicalize before any attach.
|
|
using var handle = CreateFileW(full, 0, 7, IntPtr.Zero, 3, 0x02000000, IntPtr.Zero);
|
|
if (handle.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
var buffer = new StringBuilder(512);
|
|
var length = GetFinalPathNameByHandleW(handle, buffer, (uint)buffer.Capacity, 0);
|
|
if (length == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
if (length >= buffer.Capacity)
|
|
{
|
|
if (length > 32768) throw new PathTooLongException();
|
|
buffer = new StringBuilder((int)length + 1);
|
|
length = GetFinalPathNameByHandleW(handle, buffer, (uint)buffer.Capacity, 0);
|
|
if (length == 0 || length >= buffer.Capacity) throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
}
|
|
full = WithoutDevicePrefix(buffer.ToString());
|
|
}
|
|
return Path.TrimEndingDirectorySeparator(full);
|
|
}
|
|
|
|
private static string WithoutDevicePrefix(string path)
|
|
{
|
|
if (!OperatingSystem.IsWindows()) return path;
|
|
if (path.StartsWith(@"\\?\UNC\", StringComparison.OrdinalIgnoreCase)) return @"\\" + path[8..];
|
|
return path.StartsWith(@"\\?\", StringComparison.Ordinal) ? path[4..] : path;
|
|
}
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern SafeFileHandle CreateFileW(string path, uint access, uint share, IntPtr security, uint creation, uint flags, IntPtr template);
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern uint GetFinalPathNameByHandleW(SafeFileHandle file, StringBuilder path, uint length, uint flags);
|
|
}
|