public async ETVoid Lock(long key, long instanceId, int time = 0) { if (!this.locations.TryGetValue(key, out long saveInstanceId)) { Log.Error($"actor没有注册, key: {key} InstanceId: {instanceId}"); return; } if (saveInstanceId != instanceId) { Log.Error($"actor注册的instanceId与lock的不一致, key: {key} InstanceId: {instanceId} saveInstanceId: {saveInstanceId}"); return; } CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(key + (int)AppType.Location); LockInfo lockInfo = ComponentFactory.Create <LockInfo, long, CoroutineLock>(instanceId, coroutineLock); this.lockInfos.Add(key, lockInfo); Log.Info($"location lock key: {key} InstanceId: {instanceId}"); // 超时则解锁 if (time > 0) { await Game.Scene.GetComponent <TimerComponent>().WaitAsync(time); this.UnLock(key, instanceId, instanceId); } }
public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); this.CoroutineLock.Dispose(); this.CoroutineLock = null; LockInstanceId = 0; }
public async ETVoid Lock(long key, long instanceId, int time = 0) { CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key); LockInfo lockInfo = EntityFactory.Create <LockInfo, long, CoroutineLock>(this.Domain, instanceId, coroutineLock); lockInfo.Parent = this; this.lockInfos.Add(key, lockInfo); Log.Info($"location lock key: {key} instanceId: {instanceId}"); if (time > 0) { long lockInfoInstanceId = lockInfo.InstanceId; await TimerComponent.Instance.WaitAsync(time); if (lockInfo.InstanceId != lockInfoInstanceId) { return; } UnLock(key, instanceId, instanceId); } }