36 lines
1.1 KiB
C#
Raw Normal View History

2025-11-12 18:23:37 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2025-11-18 16:43:59 +08:00
public class EventSvcLock
2025-11-12 18:23:37 +08:00
{
2025-11-18 16:43:59 +08:00
private readonly HashSet<EVENT_EXCLUSIVE_LOCK> _exclusive_lock_queue = new();
2025-11-12 18:23:37 +08:00
2025-11-18 01:08:04 +08:00
private bool GetNeedDebugLog() => CombatScenarioEventOS.Instance.GetNeedDebugLog();
2025-11-14 14:53:29 +08:00
2025-11-18 16:43:59 +08:00
public bool LOCK_APPLY(EVENT_EXCLUSIVE_LOCK lock_name) // return true 加锁成功
2025-11-12 18:23:37 +08:00
{
if (!_exclusive_lock_queue.Add(lock_name))
{
2025-11-18 16:47:44 +08:00
Debug.LogWarning($"拒绝加锁: [{lock_name}]");
2025-11-12 18:23:37 +08:00
return false;
}
2025-11-14 14:53:29 +08:00
if (GetNeedDebugLog()) Debug.Log($"申请加锁: [{lock_name}]");
2025-11-12 18:23:37 +08:00
return true;
}
2025-11-18 16:43:59 +08:00
public void LOCK_RELEASE(EVENT_EXCLUSIVE_LOCK lock_name)
2025-11-12 18:23:37 +08:00
{
if (!_exclusive_lock_queue.Contains(lock_name)) return;
_exclusive_lock_queue.Remove(lock_name);
2025-11-14 14:53:29 +08:00
if (GetNeedDebugLog()) Debug.Log($"释放解锁: [{lock_name}]");
2025-11-12 18:23:37 +08:00
}
2025-11-18 16:43:59 +08:00
public bool LOCK_GET(EVENT_EXCLUSIVE_LOCK lock_name)
2025-11-12 18:23:37 +08:00
{
2025-11-18 16:43:59 +08:00
if (!_exclusive_lock_queue.Contains(lock_name)) return false;
2025-11-18 16:47:44 +08:00
Debug.LogWarning($"状态已被锁定: [{lock_name}]");
2025-11-18 16:43:59 +08:00
return true;
2025-11-12 18:23:37 +08:00
}
}