46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
public class InitRow : MonoBehaviour
|
|
{
|
|
[SerializeField] private Toggle toggle;
|
|
[SerializeField] private TMP_Text typeText;
|
|
[SerializeField] private TMP_Text countText;
|
|
[SerializeField] private TMP_Text fromText;
|
|
[SerializeField] private TMP_Text toText;
|
|
|
|
public int EntryId { get; private set; }
|
|
public bool IsSelected => toggle != null && toggle.isOn;
|
|
|
|
public void Bind(int entryId,string typeName,int count,Vector3Int from,Vector3Int to,UnityAction<int> onClickRow,UnityAction<bool> onSelectionChanged)
|
|
{
|
|
EntryId = entryId;
|
|
|
|
if (typeText != null) typeText.text = typeName;
|
|
if (countText != null) countText.text = count.ToString();
|
|
if (fromText != null) fromText.text = $"{from.x}, {from.y}, {from.z}";
|
|
if (toText != null) toText.text = $"{to.x}, {to.y}, {to.z}";
|
|
|
|
// Row 클릭 시 선택 처리
|
|
var btn = GetComponent<Button>();
|
|
if (btn != null)
|
|
{
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(() => onClickRow?.Invoke(entryId));
|
|
}
|
|
|
|
// ✅ 토글 변경 시 Window로 알림
|
|
if (toggle != null)
|
|
{
|
|
toggle.onValueChanged.RemoveAllListeners();
|
|
toggle.onValueChanged.AddListener(onSelectionChanged);
|
|
}
|
|
}
|
|
|
|
public void SetSelected(bool on)
|
|
{
|
|
if (toggle != null) toggle.isOn = on;
|
|
}
|
|
} |