Files
XRLib/Assets/Scripts/Simulator/PropertyWindow/InitailizePopup/GridCellView.cs
2026-02-03 11:40:26 +09:00

76 lines
1.8 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public sealed class GridCellView : MonoBehaviour,
IPointerEnterHandler, IPointerClickHandler
{
[Header("UI")]
[SerializeField] private Image background;
[SerializeField] private TMP_Text label;
[SerializeField] private GameObject plusIcon; // 미리보기 선택
[SerializeField] private Image setIcon; // 확정 설정
public int RackIndex { get; private set; } // 1..z
public int X { get; private set; } // 1..layout.x
public int Y { get; private set; } // 1..layout.y
private GridView owner;
public void Init(GridView owner, int rackIndex, int x, int y)
{
this.owner = owner;
RackIndex = rackIndex;
X = x;
Y = y;
if (label != null)
label.text = "1";
SetSelecting(false);
SetOccupiedIcon(null);
}
public void SetSelecting(bool on)
{
if (plusIcon != null) plusIcon.SetActive(on);
if (on)
{
background.color = new Color(0, 1f, 0, 0.6f);
}
else
{
background.color = new Color(1, 1, 1, 1);
}
}
public void SetOccupiedIcon(Sprite sprite)
{
if (setIcon == null) return;
if (sprite == null)
{
setIcon.sprite = null;
setIcon.enabled = false;
}
else
{
setIcon.sprite = sprite;
setIcon.enabled = true;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
if (owner == null) return;
owner.OnCellPointerEnter(this);
}
public void OnPointerClick(PointerEventData eventData)
{
if (owner == null) return;
owner.OnCellPointerClick(this);
}
}