Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码
【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili
UI_ToolTip.cs
using TMPro;
using UnityEngine;
public class UI_ToolTip : MonoBehaviour
{
[SerializeField] private float xLimit = 960;
[SerializeField] private float yLimit = 540;
[SerializeField] private float xOffset = 150;
[SerializeField] private float yOffset = 150;
public virtual void AdjustPosition()//设置toolTip位置函数
{
Vector2 mousePosition = Input.mousePosition;
float newXoffset = 0;
float newYoffset = 0;
if (mousePosition.x > xLimit)
{
newXoffset = -xOffset;
}
else
{
newXoffset = xOffset;
}
if (mousePosition.y > yLimit)
{
newYoffset = -yOffset;
}
else
{
newYoffset = yOffset;
}
transform.position = new Vector2(mousePosition.x + newXoffset, mousePosition.y + newYoffset);
Debug.Log(123);
}
public void AdjustFontSize(TextMeshProUGUI _text) //调试文字大小函数
{
if(_text.text.Length > 12)
{
_text.fontSize = _text.fontSize * .8f;
}
}
}
Ui_SkillToolTip.cs
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Ui_SkillToolTip : UI_ToolTip//制作一个可以检查每个技能的描述的窗口
{
[SerializeField] private TextMeshProUGUI skillDescription;
[SerializeField] private TextMeshProUGUI skillName;
[SerializeField] private TextMeshProUGUI skillCost;
[SerializeField] private float defaultNameFontSize;
public void ShowToolTip(string _skillDescription,string _skillName,string _SkillCost)
{
skillDescription.text = _skillDescription;
skillName.text = _skillName;
skillCost.text = "Cost : " + _SkillCost;
AdjustPosition();
AdjustFontSize(skillName);
gameObject.SetActive(true);
}
public void HideToolTip()
{
skillName.fontSize = defaultNameFontSize;
gameObject.SetActive(false);
}
}
UI_SkillTreeSlot.cs
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UI_SkillTreeSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField] private int skillCost;
[SerializeField] private string skillName;
[TextArea]
[SerializeField] private string skillDescription;
[SerializeField] private Color lockedSkillColor;
private UI u