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,8 @@
fileFormatVersion: 2
guid: 47a94c1e8d71a2a46a650da8ae5d483c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,53 +0,0 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class SwapButton : MonoBehaviour, IPointerClickHandler
{
public Image TargetImage;
public Sprite ASprite;
public UnityEvent ClickEventA = new UnityEvent();
public Sprite BSprite;
public UnityEvent ClickEventB = new UnityEvent();
[SerializeField] private bool _trueA_FalseB = true;
public bool TrueA_FalseB
{
get => _trueA_FalseB;
set
{
_trueA_FalseB = value;
UpdateVisual(); // 값이 바뀔 때마다 자동으로 실행!
}
}
private void Awake()
{
TargetImage = GetComponent<Image>();
}
public void OnPointerClick(PointerEventData eventData)
{
TrueA_FalseB = !TrueA_FalseB;
if (TrueA_FalseB)
ClickEventA?.Invoke();
else
ClickEventB?.Invoke();
}
private void OnValidate()
{
UpdateVisual();
}
public void UpdateVisual()
{
if (TargetImage == null) return;
TargetImage.sprite = _trueA_FalseB ? ASprite : BSprite;
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 7742f072d8001394ca9c68f41507c667