1.进行分析,是代码逻辑清晰
2.创建Item类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 物品基类
/// </summary>
public class Item
{
public int ID { get; set; }
public string Name { get; set; }
public ItemType Type { get; set; }
public ItemQuality Quality { get; set; }
public string Description { get; set; }//描述
public int Capacity { get; set; }//容量
public int BuyPrice { get; set; }
public int SellPrice { get; set; }
public string Sprite;
/// <summary>
/// 空的构造方法
/// </summary>
public Item()
{
ID = -1;
}
/// <summary>
/// 构造方法
/// </summary>
public Item (int id,string name,ItemType type,ItemQuality quality,string des, int capacity,int buyPrice,int sellPrice,string sprite)
{
this.ID = id;
Name = name;
Type = type;
Quality = quality;
Description = des;
Capacity = capacity;
BuyPrice = buyPrice;
SellPrice = sellPrice;
this.Sprite = sprite;
}
/// <summary>
/// 物品类型
/// </summary>
public enum ItemType
{
Consumable,//消耗品
Equipment,//装备类
Weapon,//武器类
Material//材料类
}
/// <summary>
/// 物品品质
/// </summary>
public enum ItemQuality
{
Common,//普通
Uncmmon,//非凡
Rare,//稀有
Epic,//史诗
Legendary,//传奇
Artifact//神器
}
}
3.创建其他继承Item类
1.创建武器类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 武器类
/// </summary>
public class Weapon : Item
{
public int Damage { get; set; }
public WeaponType WpType { get; set; }
public Weapon(int id, string name, ItemType type, ItemQuality quality, string des, int capacity, int buyPrice, int sellPrice,string sprite,
int damage,WeaponType wpType)
: base(id, name, type, quality, des, capacity, buyPrice, sellPrice,sprite)
{
this.Damage = damage;
this.WpType = wpType;
}
/// <summary>
/// 武器类型
/// </summary>
public enum WeaponType
{
OffHand,
MainHand
}
}
2.创建消耗类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 消耗类
/// </summary>
public class Consumable : Item
{
public int HP { get; set; }
public int MP { get; set; }
public Consumable(int id, string name, ItemType type, ItemQuality quality, string des, int capacity, int buyPrice, int sellPrice,string sprite,
int hp,int mp )
: base(id, name, type, quality, des, capacity, buyPrice, sellPrice,sprite)
{
this.HP = hp;
this.MP = mp;
}
}
3.创建装备类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 装备类
/// </summary>
public class Equipment :Item
{
public int Strength { get; set; }//力量
public int Intellect { get; set; }//智力
public int Agility { get; set; }//敏捷
public int Stamina { get; set; }//体力
public EquipmentType EquipType { get; set; }//装备类型
public Equipment(int id, string name, ItemType type, ItemQuality quality, string des, int capacity, int buyPrice, int sellPrice,string sprite,
int strength,int intellect,int agility,int stamina,EquipmentType equipmentType)
:base( id, name, type, quality, des, capacity, buyPrice, sellPrice,sprite)
{
this.Strength = strength;
this.Intellect = intellect;
this.Agility = agility;
this.Stamina = stamina;
this.EquipType = equipmentType;
}
public enum EquipmentType
{
Head,//头
Neck,//脖子
Chest,//胸部
Ring,//戒指
Leg,//腿
Bracer,//护腕
Boots,//鞋子
Shoulder,//肩膀
Belt,//腰带
OffHand//副手
}
}
4.创建材料类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 材料类
/// </summary>
public class Materia : Item
{
}