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;    
    }
}

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值