com.alicizax.unity.framework/Runtime/UI/Manager/UIService.Block.cs

63 lines
1.7 KiB
C#
Raw Normal View History

using AlicizaX.Timer.Runtime;
2025-09-05 19:46:30 +08:00
using UnityEngine;
namespace AlicizaX.UI.Runtime
{
internal sealed partial class UIService
2025-09-05 19:46:30 +08:00
{
private GameObject m_LayerBlock;
private int m_LastCountDownGuid;
2025-09-05 19:46:30 +08:00
private void InitUIBlock()
{
m_LayerBlock = new GameObject("LayerBlock");
RectTransform rect = m_LayerBlock.AddComponent<RectTransform>();
2025-09-05 19:46:30 +08:00
m_LayerBlock.AddComponent<CanvasRenderer>();
m_LayerBlock.AddComponent<UIBlock>();
rect.SetParent(UICanvasRoot);
rect.SetAsLastSibling();
rect.ResetToFullScreen();
SetLayerBlockOption(false);
}
public void SetUIBlock(float timeDuration)
{
ITimerService timerService = GetTimerService();
2025-09-05 19:46:30 +08:00
if (m_LastCountDownGuid != 0)
{
timerService.RemoveTimer(m_LastCountDownGuid);
2025-09-05 19:46:30 +08:00
}
SetLayerBlockOption(true);
m_LastCountDownGuid = timerService.AddTimer(OnBlockCountDown, timeDuration);
2025-09-05 19:46:30 +08:00
}
public void ForceExitBlock()
{
ITimerService timerService = GetTimerService();
2025-09-05 19:46:30 +08:00
if (m_LastCountDownGuid != 0)
{
timerService.RemoveTimer(m_LastCountDownGuid);
2025-09-05 19:46:30 +08:00
}
RecoverLayerOptionAll();
}
2026-03-24 17:45:15 +08:00
private void OnBlockCountDown()
2025-09-05 19:46:30 +08:00
{
RecoverLayerOptionAll();
}
private void SetLayerBlockOption(bool value)
{
m_LayerBlock.SetActive(value);
}
public void RecoverLayerOptionAll()
{
SetLayerBlockOption(false);
m_LastCountDownGuid = 0;
}
}
}