2025-11-14 15:34:07 +08:00

40 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CardLockSvc
{
private readonly HashSet<CardOSData.LOCK_EXCLUSIVE_CARD_ENUM> _exclusive_lock_queue = new();
private bool GetNeedDebugLog() => CardOS.Instance.GetNeedDebugLog();
public bool LOCK_APPLY(CardOSData.LOCK_EXCLUSIVE_CARD_ENUM lock_name) // return true 加锁成功
{
if (!_exclusive_lock_queue.Add(lock_name))
{
if (GetNeedDebugLog()) Debug.LogWarning($"拒绝加锁: [{lock_name}]");
return false;
}
if (GetNeedDebugLog()) Debug.Log($"申请加锁: [{lock_name}]");
return true;
}
public void LOCK_RELEASE(CardOSData.LOCK_EXCLUSIVE_CARD_ENUM 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(CardOSData.LOCK_EXCLUSIVE_CARD_ENUM lock_name)
{
if (_exclusive_lock_queue.Contains(lock_name))
{
if (GetNeedDebugLog()) Debug.LogWarning($"状态已被锁定: [{lock_name}]");
return true;
}
return false;
}
}