49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|