Unity类银河恶魔城学习记录12-5 p127 Stat ToolTip源代码
Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考此代码仅为较上一P有所改变的代码
alex教程每一p的教程原代码加上我自己的理解初步理解写的注释,可供学习alex教程的人参考
此代码仅为较上一p有所改变的代码
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();
}
}
相关文章:
-
-
华为NPU 910B与NVIDIA GPU A100性能对比,从AICore到TensorCore,展现各自计算核心优势。…
-
-
在编辑器设置里找到.NET-编辑器-External Editor,设置为Visual Studio Code,然后点击Custom Exec Path,找到你的VSCode启动程…
-
-
_id”:“1”,best_fields类型内部会转换为(dis_max):“query”: {],通常best_fields类型使用单个最佳匹配字段的分数,但如果指定了tie_b…
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论