Unity3D背包系统制作 第01篇 物品数据

一、编辑背包物品的数据类

一般来说,背包中的物品有编号,物品名字,物品的描述,背包格子容量(也就是一个背包格子中最多可以放几个这种物品),物品的品质(普通,稀有,传说什么的),物品的类型(道具,装备,任务用品,材料等等),物品价格,至于物品的图片如何显示在格子中,有两种加载图片的方式,一个是直接加载2D图片,另一个根据Unity中Resources文件夹的功能,将图片放在Resources文件夹中,记录下图片在Resources中的保存路径,在代码中加载。

//物品的数据类
public class Item
{
    public int Id { get; private set; }                   //编号
    public string Name { get; private set; }              //名字
    public string Description { get; private set; }       //描述

    public int Capacity { get; set; }           //背包格子容量
    public ItemQuality Quality { get; set; }    //品质
    public ItemType Type { get; set; }          //类型
    public int Price { get; set; }              //价格

    public Sprite Icon_pic { get; set; }        //Icon图片
    public string Icon_str { get; set; }        //Icon图片路径

    //构造函数
    public Item(int id, string name, string description)
    {
        this.Id = id;
        this.Name = name;
        this.Description = description;
        this.Capacity = 1;
        this.Quality = ItemQuality.White;
        this.Type = ItemType.Other;
        this.Price = 0;
        this.Icon_pic = null;
        this.Icon_str = null;
    }
}

 上面用到两个枚举类型,物品的品质,物品的类型。

//物品质量
public enum ItemQuality
{
    Gray,   //灰色
    White,  //白色
    Green,  //绿色
    Blue,   //蓝色
    Purple, //紫色
    Orange, //橙色
    Yellow, //黄色
    Red,    //红色
    Black   //黑色
}

//物品类型
public enum ItemType
{
    Equip,      //装备
    Consumable, //道具
    Material,   //材料
    Task,       //任务用品
    Other
}

就这样,物品的基类就完成了。

物品中有装备,装备可以增加角色的

  • 10
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值