Files
AZTECH_WB/Assets/Scripts/UI/Library/LibraryButton.cs
정영민 b1bc41bca2 [정영민] abc 파일 오류 수정
26.03.17
- abc 파일 오류 수정
2026-03-17 10:49:06 +09:00

51 lines
1.5 KiB
C#

using AZTECHWB.Extensions;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AZTECHWB.UI
{
public class LibraryButton : MonoBehaviour
{
public Machine machine;
public event Action<LibraryButton> onClickButton;
private Image PreviewImage;
public Image Image_Selected;
public void SettingButton(Machine machine)
{
this.machine = machine;
var button = GetComponent<Button>();
var buttonText = button.GetComponentInChildren<TMP_Text>();
transform.TryGetComponentInChildren(nameof(PreviewImage), out PreviewImage);
transform.TryGetComponentInChildren(nameof(Image_Selected), out Image_Selected);
buttonText.SetText(machine.machineName);
button.onClick.AddListener(OnButtonClick);
PreviewImage.sprite = machine.previewImage;
}
private void OnButtonClick()
{
onClickButton?.Invoke(this);
}
public void OnSelected()
{
var buttonText = transform.GetComponentInChildren<TMP_Text>();
ColorUtility.TryParseHtmlString("#26C3F2", out Color color);
buttonText.color = color;
Image_Selected.gameObject.SetActive(true);
}
public void OnDeselected()
{
var buttonText = transform.GetComponentInChildren<TMP_Text>();
buttonText.color = Color.white;
Image_Selected.gameObject.SetActive(false);
}
}
}