本文主要是介绍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;}#endregionpublic 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; }
}
这篇关于Unity实战案例全解析 之 背包/贩卖/锻造系统(左侧类图实现)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!