Unity实战案例全解析 之 背包/贩卖/锻造系统(左侧类图实现)
物品类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Item
{
#region 物品类的基础属性
public int ID { get; set; }
public string Name { get; set; }
public Typeitem typeitem { get; set; }//物品类型
public Qualityitem qualityitem { get; set; }
public string Desctiption { get; set; }
public int Capacity { get; set; }
public int Buyprice { get; set; }
public int Sellprice { get; set; }
public Item() {
ID = -1;
}
#endregion
public Item(int id,string name,Typeitem t,Qualityitem q,string desctiption,int capacity,int buyprice,int sellprice)
{
this.ID = id;
this.Name = name;
this.typeitem = t;
this.qualityitem = q;
this.Desctiption = desctiption;
this.Capacity = capacity;
this.Buyprice = buyprice;
this.Sellprice = sellprice;
}
}
/// <summary>
/// 物品类型
/// </summary>
public enum Typeitem
{
Cosumable,//消耗品
Equipment,//装备
Weapon,//武器
Material//材料
}
/// <summary>
/// 品质
/// </summary>
public enum Qualityitem
{
Common,
Uncommon,
Rare,
Epic,
Legendary,
Artifact
}
其子类:
装备
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using UnityEngine;
using static UnityEditor.Experimental.GraphView.Port;
public class Equipment : Item
{
//力量
public int Strength { get; set; }
/// <summary>
/// 智力
/// </summary>
public int Intellect { get; set; }
/// <summary>
/// /敏捷
/// </summary>
public int Agility { get; set; }
/// <summary>
/// 体力
/// </summary>
public int Stamina { get; set; }
public Equipment(int id, string name, Typeitem t, Qualityitem q, string desctiption, int capacity, int buyprice, int sellprice
,int strength,int intellect, int agility,int stamina)
: base(id, name, t, q, desctiption, capacity, buyprice, sellprice)
{
this.Strength = strength;
this.Intellect = intellect;
this.Agility = agility;
this.Stamina = stamina;
}
}
public enum equipType
{
head,
neck,
chest,//胸部
ring,//戒指
leg,//腿
bracer,//护腕
boots,//靴子
shuoulder,//肩膀
belt,//腰带
offHand//副手
}
材质
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Material : Item
{
}
武器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : Item
{
public float Damage { get; set; }
public weaponType weaponType;
public Weapon(int id, string name, Typeitem t, Qualityitem q, string desctiption, int capacity, int buyprice, int sellprice, float damnage, weaponType w)
:base(id, name, t, q, desctiption, capacity, buyprice, sellprice)
{
this.Damage = damnage;
this.weaponType = w;
}
}
public enum weaponType
{
offHand,
mainHand,
}
消耗品
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Consumable : Item
{
public float Hp { get; set; }
public float Mp { get; set; }
public Consumable(int id, string name, Typeitem t, Qualityitem q, string desctiption, int capacity, int buyprice, int sellprice,float hp,float mp)
: base(id,name, t, q, desctiption, capacity, buyprice, sellprice)
{
this.Hp = hp;
this.Mp = mp;
}
}