Unity development game role entity class design

Shown below 游戏角色实体类设计.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MR_LBS.Client.Unity3D
{
    
    
    public enum MonsterUpdateCode : int
    {
    
    
        Unknown = 0,
        Create,
        Hit,
        Recover,
        Revive,
        Level,
        Health
    }
    /// <summary>
    /// 稀有度
    /// </summary>
    public enum RareGrade : int
    {
    
    
        Unknown,
        D,
        C,
        B,
        A,
        S
    };
   
    public enum MonsterDeathType : int
    {
    
    
        Unknown,
        NormalDie,
        Ice,
        BlackHole,
        SelfDestruction
    }

    /// <summary>
    /// 怪物当前的类型,特指当前稀有度下受技能影响的类型
    /// </summary>
    public enum MonsterCurrentType
    {
    
    
        /// <summary>
        /// 近战
        /// </summary>
        Melee_,
    }

    public struct NumericValue
    {
    
    
        public int monsterLevel;
        public int baseDamage;
        public int maxHealth;

        public int skill1Level;
        public int skill1Damage;

        public int skill2Level;
        public int skill2Damage;

        public int skill3Level;
        public int skill3Damage;

        public int skill4Level;
        public int skill4Damage;
    }

    //    public struct SkillNumericValue
    //    {
    
    
    //        public int level;
    //        public int damage;
    //    }

    public class MonsterItem
    {
    
    
        Monster monster;
        int count;
        bool inBox;
        public Monster Monster_P
        {
    
    
            get
            {
    
    
                return monster;
            }
            set
            {
    
    
                monster = value;
            }
        }

        public int Count
        {
    
    
            get
            {
    
    
                return count;
            }
            set
            {
    
    
                count = value;
            }
        }
        //是否由随机盒子中出现
        public bool InBox
        {
    
    
            get
            {
    
    
                return inBox;
            }

            set
            {
    
    
                inBox = value;
            }
        }
    }

    [System.Serializable]
    public class Monster
    {
    
    
        public Monster()
        {
    
    

        }
        public Monster(Monster monster)
        {
    
    
            this.Name = monster.Name;
            this.RareGrade = monster.RareGrade;
            this.Health = monster.Health;
            this.MaxHealth = monster.MaxHealth;
            this.HolyWaterConsume = monster.HolyWaterConsume;
            this.MoveSpeed = monster.MoveSpeed;


            #region Properties
            this.Attack = monster.Attack;
            this.SkillB = monster.SkillB;
            this.SkillC = monster.SkillC;
            this.SkillA = monster.SkillA;
            this.SkillS = monster.SkillS;
            this.SkillList = monster.SkillList;
            #endregion


        }

        int level;
        int maxHealth;
        int damage;
        RareGrade rareGrade;
        int holyWaterConsume;//圣水消耗值
        float moveSpeed; //移动速度,该值不变.
        string petType;//宠物类型(宠物,建筑,雇佣兵)
        float vision;//射程
        int brothers;

        NumericValue numericValue;

        public NumericValue NumericValue
        {
    
    
            get
            {
    
    
                numericValue.monsterLevel = Level;
                numericValue.maxHealth = MaxHealth;
                numericValue.baseDamage = Damage;

                if (Attack == null)
                {
    
    
                    Attack = new Skill();
                }
                //                numericValue.skill1Level = Attack.Level;
                //                numericValue.skill1Damage = Attack.Damage;

                if (SkillC == null)
                {
    
    
                    SkillC = new Skill();
                }
                numericValue.skill1Level = SkillC.Level;
                numericValue.skill1Damage = SkillC.Damage;

                if (SkillB == null)
                {
    
    
                    SkillB = new Skill();
                }
                numericValue.skill2Level = SkillB.Level;
                numericValue.skill2Damage = SkillB.Damage;
                if (SkillA == null)
                {
    
    
                    SkillA = new Skill();
                }
                numericValue.skill3Level = SkillA.Level;
                numericValue.skill3Damage = SkillA.Damage;
                if (SkillS == null)
                {
    
    
                    SkillS = new Skill();
                }
                numericValue.skill4Level = SkillS.Level;
                numericValue.skill4Damage = SkillS.Damage;
                return numericValue;
            }
            set
            {
    
    
                Level = value.monsterLevel;
                MaxHealth = value.maxHealth;
                Damage = value.baseDamage;
                numericValue = value;

                if (Attack == null)
                {
    
    
                    Attack = new Skill();
                }

                Attack.Level = numericValue.monsterLevel;
                Attack.Damage = numericValue.baseDamage;


                if (SkillC == null)
                {
    
    
                    SkillC = new Skill();
                }

                SkillC.Level = numericValue.skill1Level;
                SkillC.Damage = numericValue.skill1Damage;

                if (SkillB == null)
                {
    
    
                    SkillB = new Skill();
                }
                SkillB.Level = numericValue.skill2Level;
                SkillB.Damage = numericValue.skill2Damage;

                if (SkillA == null)
                {
    
    
                    SkillA = new Skill();
                }
                SkillA.Level = numericValue.skill3Level;
                SkillA.Damage = numericValue.skill3Damage;

                if (SkillS == null)
                {
    
    
                    SkillS = new Skill();
                }
                SkillS.Level = numericValue.skill4Level;
                SkillS.Damage = numericValue.skill4Damage;

            }
        }

        //类型,对应inventoryCode
        string sort;
        string name;
        long id;
        long uid;
        //普通攻击无等级,或者可以认为跟怪的等级一样,伤害等同于怪的基础伤害
        // Skill attack;

        List<Skill> skillList;
        Skill D;
        Skill C;

        Skill B;
        Skill A;
        Skill S;
        MonsterState state;
        MonsterDeathType deathType;
        int health;
        string des;
        GameObject body;

        public MonsterDeathType DeathType
        {
    
    
            get
            {
    
    
                return deathType;
            }
            set
            {
    
    

                deathType = value;
            }
        }

        public int Damage
        {
    
    
            get
            {
    
    
                return damage;
            }
            set
            {
    
    
                damage = value;
            }
        }

        public GameObject Body
        {
    
    
            get
            {
    
    
                return body;
            }
            set
            {
    
    
                body = value;
            }
        }

        public string Sort
        {
    
    
            get
            {
    
    
                return sort;
            }
            set
            {
    
    
                sort = value;
            }
        }

        public string Des
        {
    
    
            get
            {
    
    
                return des;
            }
            set
            {
    
    
                des = value;
            }
        }

        public long Uid
        {
    
    
            get
            {
    
    
                return uid;
            }
            set
            {
    
    
                uid = value;
            }
        }

        public long Id
        {
    
    
            get
            {
    
    
                return id;
            }
            set
            {
    
    
                id = value;
            }
        }

        public int Health
        {
    
    
            get
            {
    
    
                return health;
            }
            set
            {
    
    
                health = value;
            }
        }


        public int MaxHealth
        {
    
    
            get
            {
    
    
                return maxHealth;
            }
            set
            {
    
    
                maxHealth = value;
            }
        }

        public MonsterState State
        {
    
    
            get
            {
    
    
                return state;
            }
            set
            {
    
    
                state = value;
            }
        }

        public Skill SkillS
        {
    
    
            get
            {
    
    
                if (S == null)
                    S = new Skill();
                return S;
            }
            set
            {
    
    
                S = value;
            }
        }

        public Skill SkillA
        {
    
    
            get
            {
    
    
                if (A == null)
                    A = new Skill();
                return A;
            }
            set
            {
    
    
                A = value;
            }
        }


        public Skill SkillB
        {
    
    
            get
            {
    
    
                if (B == null)
                    B = new Skill();
                return B;
            }
            set
            {
    
    
                B = value;
            }
        }

        public Skill SkillC
        {
    
    
            get
            {
    
    
                if (C == null)
                    C = new Skill();
                return C;
            }
            set
            {
    
    
                C = value;
            }
        }

        public Skill Attack
        {
    
    
            get
            {
    
    
                return D;
            }
            set
            {
    
    
                D = value;
            }
        }

        public string Name
        {
    
    
            get
            {
    
    
                return name;
            }
            set
            {
    
    
                name = value;
            }
        }

        public int Level
        {
    
    
            get
            {
    
    
                return level;
            }
            set
            {
    
    
                level = value;
            }
        }
        public RareGrade RareGrade
        {
    
    
            get
            {
    
    
                return rareGrade;
            }
            set
            {
    
    
                rareGrade = value;
            }
        }
        public int HolyWaterConsume
        {
    
    
            get
            {
    
    
                return holyWaterConsume;
            }
            set
            {
    
    
                holyWaterConsume = value;
            }
        }
        public float MoveSpeed
        {
    
    
            get
            {
    
    
                return moveSpeed;
            }
            set
            {
    
    
                moveSpeed = value;
            }
        }

        public float Vision {
    
     get => vision; set => vision = value; }
        public List<Skill> SkillList {
    
     get => skillList; set => skillList = value; }
        public string PetType {
    
     get => petType; set => petType = value; }
        public int Brothers {
    
     get => brothers; set => brothers = value; }
    }
}

Guess you like

Origin blog.csdn.net/qq_43505432/article/details/110800928