UGUI背包(一)

这篇博客介绍了如何使用UGUI实现背包系统的基础功能,包括通过鼠标中键获取装备、显示装备详细信息、拖拽操作以及装备交换和删除。首先创建了数据类,定义了装备分类,接着制作UI界面并存储数据,确保在点击时能正确显示和操作装备。
摘要由CSDN通过智能技术生成

这里写图片描述
实现的功能:鼠标中键点击,随机获取装备名称,鼠标移到装备上,自动弹出装备的详细信息,移开自动消失,并且实现了拖拽功能(拖到区域外,默认删除,拖到有装备的默认交换)

首先第一步是 创建数据类,装备分类,有些属性是共有的,所以创建一个子类,然后不同的装备分别继承它

子类代码如下

using UnityEngine;
using System.Collections;
//共有的数据类
public class Item  {

    public int ID{ get; private set;}
    public string Name{ get; private set;}
    public string Description{ get; private set;}
    public int BUYPrice{ get; private set;}
    public int SELLPrice{ get; private set;}
    public string Icon{ get; private set;}


    public string ItemType{ get; protected set;}//道具分类用字符串或者枚举都可以,protected保证子类可以设置它

    public Item(int id,string name,string description,int buyprice,int sellprice,string icon){

        this.ID = id;
        this.Name = name;
        this.Description = description;
        this.BUYPrice = buyprice;
        this.SELLPrice = sellprice;
        this.Icon = icon;
    }
}

这里我分成了三类装备:武器,血瓶,防具

using UnityEngine;
using System.Collections;

public class Weapon : Item {
    public int gongjili{ get; private set;}

    public Weapon(int id,string name,string description,int buyprice,int sell
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值