Unity3D自学笔记——UGUI背包系统(六)角色换装及属性动态改变

角色换装及属性动态改变

同样利用了Attribute设计,其实角色这里已经很简单了

效果图

白属性
这里写图片描述
装备剑, 攻击力+10
这里写图片描述
装备匕首,攻击力+8
这里写图片描述
装备三级匕首,攻击加24
这里写图片描述

同样角色属性的改变是通过之前写的PlayerStatus进行赋值

大致示意图

这里写图片描述

思路

通过装备按钮,更改PlayerStatus的装备属性,并重新计算角色总属性,然后触发PlayerStatus的换装事件,通知角色属性面板刷新。

弹出框修改

同样,界面绑定都从ItemStaus取值,在装备按钮事件中首先改变PlayerStatus的对应属性,这里是Weapon

public class UIItemToolTip : UIScene {
    private Image m_Icon;
    private Text m_NameText;
    private Text m_LvText;
    private Text m_TypeText;
    private Text m_DescriptionText;
    private Text m_AttributeText;
    private Text m_BtnDressOnText;
    private Text m_BtnDropText;
    private Text m_RedPriceText;
    private Text m_BluePriceText;

    private UISceneWidget m_BtnClose;
    private UISceneWidget m_BtnDressOn;
    private UISceneWidget m_BtnDrop;
    private ItemStatus m_ItemStatus;
    private PlayerStatus m_PlayerStatus;

    void Awake()
    {
        this.m_Icon = UIHelper.FindChild<Image>(transform, "imgIcon/Image");
        this.m_NameText = UIHelper.FindChild<Text>(transform, "txtName");
        this.m_LvText = UIHelper.FindChild<Text>(transform, "txtLv");
        this.m_TypeText = UIHelper.FindChild<Text>(transform, "txtType");
        this.m_DescriptionText = UIHelper.FindChild<Text>(transform, "txtDescription");
        this.m_AttributeText = UIHelper.FindChild<Text>(transform, "imgAttribute/txtAttribute");
        this.m_BtnDressOnText = UIHelper.FindChild<Text>(transform, "btnDressOn/Text");
        this.m_BtnDropText = UIHelper.FindChild<Text>(transform, "btnDrop/Text");
        this.m_BluePriceText = UIHelper.FindChild<Text>(transform, "txtBluePrice");
        this.m_RedPriceText = UIHelper.FindChild<Text>(transform, "txtRedPrice");
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        this.m_PlayerStatus = player.GetComponent<PlayerStatus>();
    }

    protected override void Start()
    {
        base.Start();
        m_BtnClose = this.GetWidget("btnClose");
        if(m_BtnClose != null)
            m_BtnClose.PointerClick += BtnClosePointerClick;
        m_BtnDressOn = this.GetWidget("btnDressOn");
        if(m_BtnDressOn != null)
            m_BtnDressOn.PointerClick += BtnDressOnPointerClick;
        m_BtnDrop = this.GetWidget("btnDrop");
        if(m_BtnDrop != null)
            m_BtnDrop.PointerClick += BtnDropPointerClick;
    }

    public void Show(ItemStatus itemStatus, bool isLeft)
    {
        this.SetVisible(true);
        this.m_ItemStatus = itemStatus;
        this.m_Icon.overrideSprite = Resources.Load<Sprite>(m_ItemStatus.IconPath);
        this.m_NameText.text = m_ItemStatus.ItemName;
        this.m_DescriptionText.text = m_ItemStatus.Description;
        this.m_LvText.text = string.Format("等级: {0}", m_ItemStatus.Lv);
        this.m_TypeText.text = m_ItemStatus.ItemTypeString;
        this<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值