当前位置: 代码网 > it编程>编程语言>Asp.net > Unity类银河恶魔城学习记录12-5 p127 Stat ToolTip源代码

Unity类银河恶魔城学习记录12-5 p127 Stat ToolTip源代码

2024年08月01日 Asp.net 我要评论
Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考此代码仅为较上一P有所改变的代码

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();
    }
}

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com