一、编辑背包物品的数据类
一般来说,背包中的物品有编号,物品名字,物品的描述,背包格子容量(也就是一个背包格子中最多可以放几个这种物品),物品的品质(普通,稀有,传说什么的),物品的类型(道具,装备,任务用品,材料等等),物品价格,至于物品的图片如何显示在格子中,有两种加载图片的方式,一个是直接加载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
}
就这样,物品的基类就完成了。
物品中有装备,装备可以增加角色的