3fc3399032
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Successful in 6m41s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Successful in 7m8s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Successful in 7m16s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Successful in 7m38s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 2m11s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 3m11s
Project CI / Repository checks (pull_request) Successful in 4m22s
Project CI / Frontend tests (pull_request) Successful in 5m52s
Project CI / Native shell tests (pull_request) Successful in 9m52s
Project CI / Backend tests (pull_request) Successful in 11m3s
Project CI / AI game creator shell web tests (pull_request) Successful in 6m41s
新增内置 Unity 插件与自包含 Attach helper,固定上游版本并保留许可证 统一 Runner 执行归属、项目身份校验、回执确认和不确定结果阻断 接入 Unity 工程导入、Agent 工具目录及 Windows 构建分发 补齐插件测试、CI 执行入口和 Windows .NET 10 工具链检查 记录真实 Unity 连接、执行、重载恢复及 Runner 边界验证
92 lines
3.7 KiB
C#
92 lines
3.7 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
|
|
#if DOTCRAFT_ATTACH
|
|
namespace DotCraft.Unity
|
|
#else
|
|
namespace DotCraft.Editor
|
|
#endif
|
|
{
|
|
public sealed class UnityExecutionContext
|
|
{
|
|
readonly CancellationToken cancellationToken;
|
|
readonly Action<UnityExecutionContext, Action, int, double, Func<bool>> schedule;
|
|
Exception waitError;
|
|
bool invalidated;
|
|
|
|
public UnityExecutionContext(CancellationToken cancellationToken, Action<UnityExecutionContext, Action, int, double, Func<bool>> schedule)
|
|
{
|
|
this.cancellationToken = cancellationToken;
|
|
this.schedule = schedule ?? throw new ArgumentNullException(nameof(schedule));
|
|
}
|
|
|
|
public CancellationToken CancellationToken { get { return cancellationToken; } }
|
|
public bool IsCancellationRequested { get { return invalidated || cancellationToken.IsCancellationRequested; } }
|
|
public UnityAwaitable WaitFrame() { return new UnityAwaitable(this, 1, 0, null); }
|
|
public UnityAwaitable WaitFrames(int frames) { return new UnityAwaitable(this, Math.Max(1, frames), 0, null); }
|
|
public UnityAwaitable WaitSeconds(float seconds) { return new UnityAwaitable(this, 1, Math.Max(0, seconds), null); }
|
|
public UnityAwaitable WaitUntil(Func<bool> predicate)
|
|
{
|
|
if (predicate == null) throw new ArgumentNullException("predicate");
|
|
return new UnityAwaitable(this, 1, 0, predicate);
|
|
}
|
|
public void ThrowIfCancellationRequested()
|
|
{
|
|
if (invalidated) throw new OperationCanceledException("Unity execution domain is no longer available.");
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
if (waitError == null) return;
|
|
var error = waitError;
|
|
waitError = null;
|
|
throw error;
|
|
}
|
|
internal void Invalidate() { invalidated = true; }
|
|
internal bool Evaluate(Func<bool> predicate)
|
|
{
|
|
if (predicate == null) return true;
|
|
try { return predicate(); }
|
|
catch (Exception e) { waitError = e; return true; }
|
|
}
|
|
internal void Schedule(Action continuation, int frames, double seconds, Func<bool> predicate)
|
|
{
|
|
schedule(this, continuation, frames, seconds, predicate);
|
|
}
|
|
}
|
|
|
|
public struct UnityAwaitable
|
|
{
|
|
readonly UnityExecutionContext context;
|
|
readonly int frames;
|
|
readonly double seconds;
|
|
readonly Func<bool> predicate;
|
|
|
|
internal UnityAwaitable(UnityExecutionContext context, int frames, double seconds, Func<bool> predicate)
|
|
{
|
|
this.context = context;
|
|
this.frames = frames;
|
|
this.seconds = seconds;
|
|
this.predicate = predicate;
|
|
}
|
|
|
|
public Awaiter GetAwaiter() { return new Awaiter(context, frames, seconds, predicate); }
|
|
|
|
public struct Awaiter : INotifyCompletion
|
|
{
|
|
readonly UnityExecutionContext context;
|
|
readonly int frames;
|
|
readonly double seconds;
|
|
readonly Func<bool> predicate;
|
|
internal Awaiter(UnityExecutionContext context, int frames, double seconds, Func<bool> predicate)
|
|
{
|
|
this.context = context;
|
|
this.frames = frames;
|
|
this.seconds = seconds;
|
|
this.predicate = predicate;
|
|
}
|
|
public bool IsCompleted { get { return false; } }
|
|
public void OnCompleted(Action continuation) { context.Schedule(continuation, frames, seconds, predicate); }
|
|
public void GetResult() { context.ThrowIfCancellationRequested(); }
|
|
}
|
|
}
|
|
}
|