40 lines
1.2 KiB
C#
Raw Normal View History

2025-11-12 18:23:37 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CardLockSvc
{
2025-11-12 18:35:43 +08:00
private readonly HashSet<CardOSData.LOCK_EXCLUSIVE_CARD_ENUM> _exclusive_lock_queue = new();
2025-11-12 18:23:37 +08:00
2025-11-14 14:53:29 +08:00
private bool GetNeedDebugLog() => CardOS.Instance.GetNeedDebugLog();
2025-11-14 15:34:07 +08:00
public bool LOCK_APPLY(CardOSData.LOCK_EXCLUSIVE_CARD_ENUM lock_name) // return true 加锁成功
2025-11-12 18:23:37 +08:00
{
if (!_exclusive_lock_queue.Add(lock_name))
{
2025-11-14 14:53:29 +08:00
if (GetNeedDebugLog()) 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-12 18:35:43 +08:00
public void LOCK_RELEASE(CardOSData.LOCK_EXCLUSIVE_CARD_ENUM 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-12 18:35:43 +08:00
public bool LOCK_GET(CardOSData.LOCK_EXCLUSIVE_CARD_ENUM lock_name)
2025-11-12 18:23:37 +08:00
{
2025-11-14 14:53:29 +08:00
if (_exclusive_lock_queue.Contains(lock_name))
{
if (GetNeedDebugLog()) Debug.LogWarning($"状态已被锁定: [{lock_name}]");
return true;
}
return false;
2025-11-12 18:23:37 +08:00
}
}