My Classes for Party Member Info and Enemy Info

Hello,
First off, I just want to say that I am enjoying the class, and am learning new ways to do things in Unity that I have not done before.

Second, since I have some experience in Unity (mostly from other GameDev.tv tutorials), I started planning ahead for a game with more stats (magic, defenses, etc.) so I wanted to share my approach to these classes in case anyone else wants to use some of the ideas for themselves.

CharacterInfo.cs (PartyMemberInfo in the tutorial)

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

[CreateAssetMenu(menuName = "New Character Information")]
public class CharacterInfo : ScriptableObject
{
    public string CharacterName;

    //Character Information
    [Serializable]
    public struct VitalInformation
    {
        public int CharacterLevel;
        public int Experience;

        public int MaxHealth;
        public int MaxMana;
    }

    [Serializable]
    public struct VitalGrowth
    {
        public GrowthRate HealthGrowthRate;
        public GrowthRate ManaGrowthRate;
    }


    //Character Stats
    [Serializable]
    public struct StatBlock
    {
        public int Strength;
        public int Magic;
        public int Speed;
        public int Endurance;
        public int Fortitude;
        public int Luck;
    }

    [Serializable]
    public struct StatGrowth
    {
        public GrowthRate StrengthGrowthRate;
        public GrowthRate MagicGrowthRate;
        public GrowthRate SpeedGrowthRate;
        public GrowthRate EnduranceGrowthRate;
        public GrowthRate FortitudeGrowthRate;
        public GrowthRate LuckGrowthRate;
    }

    [Header("Vitality Information")]
    public VitalInformation Vitals;
    public VitalGrowth VitalsGrowthRate;

    [Header("Stat Block Information")]
    public StatBlock Stats;
    public StatGrowth StatsGrowRate;

    [Header("Visual Prefabs")]
    //Visuals
    public GameObject ExplorationVisualPrefab;
    public GameObject BattleVisualPrefab;

    public enum GrowthRate
    {
        F = 7,
        E = 6,
        D = 5,
        C = 4,
        B = 3,
        A = 2,
        S = 1
    };
}

I added structures to contain the various elements that make up a character, such as the Level, HP MP, and another structure to make up the Stats (things like Strength, Speed, Endurance, etc). I found that this not only helps keep the information organized in the editor, it also eases the number of assignment statements needed to copy all the information into the PartyMember fields.

The EnemyInfo class simply inherits the CharacterInfo class, which also increases efficiencyPreformatted text.

[CreateAssetMenu(menuName = "New Enemy Information")]
public class EnemyInfo : CharacterInfo
{
    public int ExperienceGiven;
}

I simply added a variable to indicate how much exp they award on defeat.

Lastly, the PartyManager / PartyMember classes can be sped up by using the structures defined in the CharacterInfo class.

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

public class PartyManager : MonoBehaviour
{
    [SerializeField] private List<CharacterInfo> allCharacters;
    [SerializeField] private List<PartyMember> currentParty;

    [SerializeField] private CharacterInfo defaultCharacterInfo;

    private void Awake()
    {
        currentParty = new List<PartyMember>();

        AddCharacterToPartyByName(defaultCharacterInfo.CharacterName);
    }

    public void AddCharacterToPartyByName(string characterName)
    {
        CharacterInfo charInfo = allCharacters.Find(character => character.CharacterName == characterName);

        if (charInfo == null)
            return;

        PartyMember newPartyMember = new PartyMember()
        {
            CharacterName = charInfo.CharacterName,

            Vitals = charInfo.Vitals,
            VitalsGrowthRate = charInfo.VitalsGrowthRate,

            Stats = charInfo.Stats,
            StatsGrowthRate = charInfo.StatsGrowRate,

            ExplorationVisualPrefab = charInfo.ExplorationVisualPrefab,
            BattleVisualPrefab = charInfo.BattleVisualPrefab
        };

        currentParty.Add(newPartyMember);
    }
}

[Serializable]
public class PartyMember
{
    public string CharacterName;

    [Header("Vitality Information")]
    public CharacterInfo.VitalInformation Vitals;
    public CharacterInfo.VitalGrowth VitalsGrowthRate;

    [Header("Stat Block Information")]
    public CharacterInfo.StatBlock Stats;
    public CharacterInfo.StatGrowth StatsGrowthRate;

    [Header("Visual Prefabs")]
    public GameObject ExplorationVisualPrefab;
    public GameObject BattleVisualPrefab;
}

With this, you can easily add any values in a logical way to these structures, and those changes will be made in the helper classes as well.

Below is a picture of the editor with these structures, showing how everything is laid out.


Privacy & Terms