Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码
【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili
UI.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UI : MonoBehaviour
{
[SerializeField] private GameObject characterUI;
public UI_itemTooltip itemTooltip;
public void Start()
{
itemTooltip = characterUI.GetComponentInChildren<UI_itemTooltip>();
}
public void SwitchTo(GameObject _menu)
{
for(int i = 0;i < transform.childCount;i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
if(_menu != null)
{
_menu.SetActive(true);
}
}
}
UI_itemTooltip.cs
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class UI_itemTooltip : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI itemNameText;
[SerializeField] private TextMeshProUGUI itemTypeText;
[SerializeField] private TextMeshProUGUI itemDescription;
[SerializeField] private int defaultFontSize = 32;
public void ShowToolTip(ItemData_Equipment item)//将item里面的数据读取到对应的text上并显示此组件
{
if (item == null)
return;
itemNameText.text = item.itemName;
itemTypeText.text = item.equipmentType.ToString();
itemDescription.text = item.GetDescription();
if (itemNameText.text.Length > 12)//使标题超过最大尺寸时字体缩小
{