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 ui_stattooltip stattooptip;
public void start()
{
//itemtooltip = characterui.getcomponentinchildren<ui_itemtooltip>();
//stattooptip = characterui.getcomponentinchildren<ui_stattooltip>();
}
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_stattooltip.cs
using system.collections;
using system.collections.generic;
using tmpro;
using unityengine;
public class ui_stattooltip : monobehaviour
{
[serializefield] private textmeshprougui description;
public void showstattooltip(string _text)
{
debug.log(3);
if (_text == null)
return;
debug.log(4);
description.text = _text;
gameobject.setactive(true);
}
public void hidestattooltip()
{
description.text = "";
gameobject.setactive(false);
}
}
ui_statslot.cs
using system.collections;
using system.collections.generic;
using tmpro;
using unityengine;
using unityengine.eventsystems;
public class ui_statslot : monobehaviour,ipointerenterhandler,ipointerexithandler
{
private ui ui;
[serializefield] private stattype stattype;
[serializefield] private textmeshprougui statvaluetext;
[serializefield] private textmeshprougui statnametext;
[textarea]
[serializefield] private string statdescription;
private void onvalidate()
{
gameobject.name = "stat - " + stattype.tostring();
if(statnametext != null)
{
statnametext.text = stattype.tostring();
}
}
private void start()
{
updatestatvalueui();
ui = getcomponentinparent<ui>();
}
public void updatestatvalueui()
{
playerstats playerstats = playermanager.instance.player.getcomponent<playerstats>();
if(playerstats != null)
{
statvaluetext.text = playerstats.getstats(stattype).getvalue().tostring();
if (stattype == stattype.health)
statvaluetext.text = playerstats.getmaxhealthvalue().tostring();
if (stattype == stattype.damage)
statvaluetext.text = (playerstats.damage.getvalue()+playerstats.strength.getvalue()).tostring();
if (stattype == stattype.critpower)
statvaluetext.text = (playerstats.critpower.getvalue() + playerstats.strength.getvalue()).tostring();
if (stattype == stattype.critchance)
statvaluetext.text = (playerstats.critchance.getvalue() + playerstats.agility.getvalue()).tostring();
if (stattype == stattype.evasion)
statvaluetext.text = (playerstats.evasion.getvalue() + playerstats.agility.getvalue()).tostring();
if (stattype == stattype.magicresistance)
statvaluetext.text = (playerstats.magicresistance.getvalue() + playerstats.intelligence.getvalue()*3).tostring();
}
}
public void onpointerenter(pointereventdata eventdata)
{
if (statdescription == null)
return;
debug.log("1");
ui.stattooptip.showstattooltip(statdescription);
}
public void onpointerexit(pointereventdata eventdata)
{
debug.log("2");
ui.stattooptip.hidestattooltip();
}
}
发表评论