2026-03-22 스왑버튼 그룹구현

This commit is contained in:
2026-03-22 18:57:56 +09:00
parent e0116ec98c
commit faf692673d
10 changed files with 182 additions and 53 deletions

View File

@@ -0,0 +1,48 @@
using System.Collections.Generic;
using UnityEngine;
[ExecuteAlways]
public class SwapButtonGroup : MonoBehaviour
{
// 현재 이 그룹에 등록된 모든 버튼들
private List<SwapButton> _registeredButtons = new List<SwapButton>();
// 버튼이 활성화되거나 그룹이 할당될 때 호출됨
public void RegisterButton(SwapButton button)
{
if (!_registeredButtons.Contains(button))
{
_registeredButtons.Add(button);
if (button.TrueA_FalseB == true)
{
foreach (SwapButton sb in _registeredButtons)
{
if (sb == button) continue;
sb.TrueA_FalseB = false;
}
}
}
}
// 버튼이 파괴되거나 그룹에서 빠질 때 호출됨
public void UnregisterButton(SwapButton button)
{
if (_registeredButtons.Contains(button))
{
_registeredButtons.Remove(button);
}
}
// 특정 버튼이 선택되었을 때 나머지 버튼들을 모두 B(False)상태로 만듦
public void OnButtonSelected(SwapButton selectedButton)
{
foreach (SwapButton button in _registeredButtons)
{
if (button == selectedButton) continue;
button.TrueA_FalseB = false;
}
}
}