36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EventSvcLock
|
|
{
|
|
private readonly HashSet<EVENT_EXCLUSIVE_LOCK> _exclusive_lock_queue = new();
|
|
|
|
private bool GetNeedDebugLog() => CombatScenarioEventOS.Instance.GetNeedDebugLog();
|
|
|
|
public bool LOCK_APPLY(EVENT_EXCLUSIVE_LOCK lock_name) // return true 加锁成功
|
|
{
|
|
if (!_exclusive_lock_queue.Add(lock_name))
|
|
{
|
|
Debug.LogWarning($"拒绝加锁: [{lock_name}]");
|
|
return false;
|
|
}
|
|
|
|
if (GetNeedDebugLog()) Debug.Log($"申请加锁: [{lock_name}]");
|
|
return true;
|
|
}
|
|
|
|
public void LOCK_RELEASE(EVENT_EXCLUSIVE_LOCK lock_name)
|
|
{
|
|
if (!_exclusive_lock_queue.Contains(lock_name)) return;
|
|
_exclusive_lock_queue.Remove(lock_name);
|
|
if (GetNeedDebugLog()) Debug.Log($"释放解锁: [{lock_name}]");
|
|
}
|
|
|
|
public bool LOCK_GET(EVENT_EXCLUSIVE_LOCK lock_name)
|
|
{
|
|
if (!_exclusive_lock_queue.Contains(lock_name)) return false;
|
|
Debug.LogWarning($"状态已被锁定: [{lock_name}]");
|
|
return true;
|
|
}
|
|
} |