```
feat(gameplay): 更新单位属性和材质配置 - 调整多个单位的基础生命值和攻击力数值平衡 - 修改CoreBattleGround材质的纹理缩放比例 - 更新地砖材质颜色为白色 - 优化纹理资源设置,调整最大纹理尺寸并添加PlayableAds平台支持 - 修复弓箭手技能目标查找逻辑,改用统一的敌人检测方法 - 为水晶矿添加中立阵营设置和光球视觉效果同步 - 调整预制体中的全局缩放参数 - 为狼人和石巨人添加NavMeshAgent组件支持 - 优化水晶矿血条显示位置计算方式 ```
This commit is contained in:
1 parent
0e7de5f885
commit
53d95802e5
448 files changed
+133333
-472
No files matched your search
+95
@@ -0,0 +1,95 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityTcp.Editor.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Thread-safe index of every in-flight runner job, keyed by job id and by the native request
|
||||
/// id that started it. The request-id index is what lets a client detach a job it has not yet
|
||||
/// received a job id for — it always knows the request id of the call it is stuck waiting on.
|
||||
///
|
||||
/// Runners register on enroll (and <see cref="StepJobRunner"/> re-registers restored jobs
|
||||
/// after a domain reload) and unregister when the job leaves their registry. The handle a
|
||||
/// runner registers is what makes cross-thread detach possible: its
|
||||
/// <see cref="IJobHandle.TryDetach"/> touches only thread-safe state (the
|
||||
/// <see cref="JobContext"/> delivery gate, <see cref="DetachedJobs"/>, the native response
|
||||
/// queue), never the runner's main-thread-only job list.
|
||||
/// </summary>
|
||||
public static class JobRegistry
|
||||
{
|
||||
/// <summary>A registered in-flight job, with the thread-safe detach entry point.</summary>
|
||||
public interface IJobHandle
|
||||
{
|
||||
string JobId { get; }
|
||||
ulong RequestId { get; }
|
||||
string Name { get; }
|
||||
/// <summary>Owning runner: "step", "task", or "coroutine".</summary>
|
||||
string Runner { get; }
|
||||
bool Detached { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the job: answers its original request with a detach ack carrying the job
|
||||
/// id, after which the outcome lands in <see cref="DetachedJobs"/> for polling.
|
||||
/// Callable from any thread. Returns false (with an explanation) when the job was
|
||||
/// already detached or already answered.
|
||||
/// </summary>
|
||||
bool TryDetach(string reason, out string error);
|
||||
}
|
||||
|
||||
private static readonly ConcurrentDictionary<string, IJobHandle> _byJobId =
|
||||
new ConcurrentDictionary<string, IJobHandle>();
|
||||
private static readonly ConcurrentDictionary<ulong, string> _jobIdByRequestId =
|
||||
new ConcurrentDictionary<ulong, string>();
|
||||
|
||||
internal static void Register(IJobHandle handle)
|
||||
{
|
||||
if (handle == null || string.IsNullOrEmpty(handle.JobId)) return;
|
||||
_byJobId[handle.JobId] = handle;
|
||||
if (handle.RequestId != 0)
|
||||
_jobIdByRequestId[handle.RequestId] = handle.JobId;
|
||||
}
|
||||
|
||||
internal static void Unregister(string jobId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jobId)) return;
|
||||
if (_byJobId.TryRemove(jobId, out var handle) && handle.RequestId != 0)
|
||||
{
|
||||
// Only drop the request mapping if it still points at this job — a handed-off job
|
||||
// re-registers under the same request id before the old runner unregisters.
|
||||
if (_jobIdByRequestId.TryGetValue(handle.RequestId, out string mapped) && mapped == jobId)
|
||||
_jobIdByRequestId.TryRemove(handle.RequestId, out _);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGet(string jobId, out IJobHandle handle)
|
||||
{
|
||||
handle = null;
|
||||
return !string.IsNullOrEmpty(jobId) && _byJobId.TryGetValue(jobId, out handle);
|
||||
}
|
||||
|
||||
public static bool TryGetByRequestId(ulong requestId, out IJobHandle handle)
|
||||
{
|
||||
handle = null;
|
||||
return requestId != 0
|
||||
&& _jobIdByRequestId.TryGetValue(requestId, out string jobId)
|
||||
&& _byJobId.TryGetValue(jobId, out handle);
|
||||
}
|
||||
|
||||
/// <summary>Snapshot of every in-flight job, for <c>manage_job.list</c>.</summary>
|
||||
public static List<IJobHandle> Snapshot()
|
||||
{
|
||||
var result = new List<IJobHandle>();
|
||||
foreach (var kv in _byJobId)
|
||||
result.Add(kv.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int Count => _byJobId.Count;
|
||||
|
||||
internal static void Clear()
|
||||
{
|
||||
_byJobId.Clear();
|
||||
_jobIdByRequestId.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user