157 lines
4.3 KiB
C#
157 lines
4.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using TMPro;
|
|
using Northbound.Data;
|
|
|
|
namespace Northbound
|
|
{
|
|
/// <summary>
|
|
/// 개별 건물 슬롯 버튼
|
|
/// </summary>
|
|
[RequireComponent(typeof(EventTrigger))]
|
|
public class BuildingSlotButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[Header("UI References")]
|
|
[SerializeField] private Image iconImage;
|
|
[SerializeField] private TextMeshProUGUI nameText;
|
|
[SerializeField] private TextMeshProUGUI hotkeyText;
|
|
[SerializeField] private Image backgroundImage;
|
|
[SerializeField] private Button button;
|
|
|
|
[Header("Visual Settings")]
|
|
[SerializeField] private Color normalColor = new Color(0.2f, 0.2f, 0.2f, 0.8f);
|
|
[SerializeField] private Color selectedColor = new Color(0.3f, 0.6f, 0.3f, 1f);
|
|
[SerializeField] private Color hoverColor = new Color(0.3f, 0.3f, 0.3f, 1f);
|
|
|
|
private TowerData buildingData;
|
|
private int slotIndex;
|
|
private BuildingQuickslotUI quickslotUI;
|
|
private bool isSelected = false;
|
|
|
|
private void Awake()
|
|
{
|
|
if (button == null)
|
|
button = GetComponent<Button>();
|
|
|
|
if (button != null)
|
|
{
|
|
button.onClick.AddListener(OnButtonClicked);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 슬롯 초기화
|
|
/// </summary>
|
|
public void Initialize(TowerData data, int index, BuildingQuickslotUI ui)
|
|
{
|
|
buildingData = data;
|
|
slotIndex = index;
|
|
quickslotUI = ui;
|
|
|
|
UpdateVisuals();
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI 업데이트
|
|
/// </summary>
|
|
private void UpdateVisuals()
|
|
{
|
|
if (buildingData == null) return;
|
|
|
|
// 아이콘 설정
|
|
/*
|
|
if (iconImage != null && buildingData.icon != null)
|
|
{
|
|
iconImage.sprite = buildingData.icon;
|
|
iconImage.enabled = true;
|
|
}
|
|
else if (iconImage != null)
|
|
{
|
|
iconImage.enabled = false;
|
|
}
|
|
*/
|
|
iconImage.enabled = false;
|
|
// 이름 설정
|
|
if (nameText != null)
|
|
{
|
|
nameText.text = buildingData.buildingName;
|
|
}
|
|
|
|
// 배경 색상
|
|
UpdateBackgroundColor();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 핫키 텍스트 설정
|
|
/// </summary>
|
|
public void SetHotkeyText(string text)
|
|
{
|
|
if (hotkeyText != null)
|
|
{
|
|
hotkeyText.text = text;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 버튼 클릭 이벤트
|
|
/// </summary>
|
|
private void OnButtonClicked()
|
|
{
|
|
if (quickslotUI != null)
|
|
{
|
|
quickslotUI.SelectBuilding(slotIndex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 선택 상태 설정
|
|
/// </summary>
|
|
public void SetSelected(bool selected)
|
|
{
|
|
isSelected = selected;
|
|
UpdateBackgroundColor();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 배경 색상 업데이트
|
|
/// </summary>
|
|
private void UpdateBackgroundColor()
|
|
{
|
|
if (backgroundImage != null)
|
|
{
|
|
backgroundImage.color = isSelected ? selectedColor : normalColor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 마우스 호버 시 (IPointerEnterHandler)
|
|
/// </summary>
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (backgroundImage != null && !isSelected)
|
|
{
|
|
backgroundImage.color = hoverColor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 마우스 호버 해제 시 (IPointerExitHandler)
|
|
/// </summary>
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (backgroundImage != null && !isSelected)
|
|
{
|
|
backgroundImage.color = normalColor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 건물 이름 반환
|
|
/// </summary>
|
|
public string GetBuildingName()
|
|
{
|
|
return buildingData != null ? buildingData.buildingName : "Unknown";
|
|
}
|
|
}
|
|
} |