养成基本完毕,新UI,修bug,装备初步,
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class materialPrefab : MonoBehaviour
|
||||
{
|
||||
[Header("imgs")]
|
||||
public Image boarder;
|
||||
public Image materialImg;
|
||||
public Button materialButton;
|
||||
public TextMeshProUGUI materialAmount;
|
||||
public Text materialName;
|
||||
|
||||
private Action clickAction;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (materialButton != null)
|
||||
{
|
||||
materialButton.onClick.RemoveListener(HandleClick);
|
||||
materialButton.onClick.AddListener(HandleClick);
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Sprite sprite, string displayName, string amountText, bool selected, bool interactable, Action onClick)
|
||||
{
|
||||
clickAction = onClick;
|
||||
|
||||
if (materialImg != null)
|
||||
{
|
||||
materialImg.sprite = sprite;
|
||||
materialImg.enabled = sprite != null;
|
||||
}
|
||||
|
||||
if (materialName != null)
|
||||
{
|
||||
materialName.text = displayName ?? string.Empty;
|
||||
}
|
||||
|
||||
if (materialAmount != null)
|
||||
{
|
||||
materialAmount.text = amountText ?? string.Empty;
|
||||
}
|
||||
|
||||
SetSelected(selected);
|
||||
|
||||
if (materialButton != null)
|
||||
{
|
||||
materialButton.interactable = interactable;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSelected(bool selected)
|
||||
{
|
||||
if (boarder != null)
|
||||
{
|
||||
boarder.enabled = selected;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleClick()
|
||||
{
|
||||
if (materialButton != null && !materialButton.interactable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (clickAction != null)
|
||||
{
|
||||
clickAction.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user