56 lines
1.1 KiB
C#
56 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class itemInfo : MonoBehaviour
|
|
{
|
|
[Header("显示物品的image")]
|
|
public Image iconImage;
|
|
[Header("物品名的TextPro")]
|
|
public TextMeshProUGUI nameText;
|
|
[Header("物品价格的TextPro")]
|
|
public TextMeshProUGUI priceText;
|
|
|
|
[Header("可以按下的按钮")]
|
|
public Button btn;
|
|
[Header("按下按钮显示的界面")]
|
|
public GameObject prefab;
|
|
|
|
|
|
|
|
private int id;//item id
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
btn.onClick.AddListener(()=> {
|
|
|
|
GameObject.Instantiate(prefab,GameObject.Find("Canvas").transform);
|
|
});
|
|
}
|
|
|
|
public void init(int id)
|
|
{
|
|
this.id = id;
|
|
}
|
|
|
|
public void initShow(int id, Sprite icon, string name, string price)
|
|
{
|
|
this.id = id;
|
|
iconImage.sprite = icon;
|
|
nameText.text = name;
|
|
priceText.text = price;
|
|
}
|
|
|
|
public void initShow(int id, string name, string price)
|
|
{
|
|
this.id = id;
|
|
nameText.text = name;
|
|
priceText.text = price;
|
|
}
|
|
|
|
}
|