UnityGameProjectsCode / RelianceGame / Save Data Control / SaveGameData.cs
SaveGameData.cs
Raw
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class SaveGameData //holds all save data for a specific save game
{
    //file information that will appear on the save game prefab
    public string fileNameText;
    public int hours, minutes, seconds, totalTimeInSeconds;
    public int datumValue;
    public int creditsValue;
    public int botLevelValue;

    [System.Serializable]
    public struct PlayerInfo //holds info about the player and their bots stats
    {
        public int points;
        public int level;
        public int exp;
        public int strength;
        public int electronics;
        public int agility;
        public int combat;
        public int scanning;
        public int efficiency;
        public int heavyHitter;
        public int retention;
        public int defender;
        public int objMaster;
        public int regenerator;
        public int lucky;
        public int teamPlayer;
        public int informant;
        public string spec;

        public int perk1;
        public int perk2;
        public int perk3;
        public int perk4;
        public int perk5;
        public int perk6;
    };

    [System.Serializable]
    public struct ItemInfo //struct with info to identify specific items
    {
        public int itemID;
        public int slotPosition;
        public bool equipped;
        public int ownerID;
    };

    [System.Serializable]
    public struct missionInfo
    {
        public string missionName;
        public string missionDesc;
        public string factionName;
        public string difficulty;
        public int rewards1;
        public int rewards2;
    };

    public List<missionInfo> missions = new List<missionInfo>();

    //shop item lists
    public List<int> armoryItemIDs = new List<int>();
    public List<int> junkItemIDs = new List<int>();
    public List<int> weaponItemIDs = new List<int>();
    public List<int> specialItemIDs = new List<int>();

    //equipment/inventory structs
    public List<ItemInfo> leadEquipment = new List<ItemInfo>();
    public List<ItemInfo> blueEquipment = new List<ItemInfo>();
    public List<ItemInfo> greenEquipment = new List<ItemInfo>();
    public List<ItemInfo> orangeEquipment = new List<ItemInfo>();
    public List<ItemInfo> loadoutInventory = new List<ItemInfo>();

    //player/bot stats structs
    public PlayerInfo leadBot = new PlayerInfo();
    public PlayerInfo blueBot = new PlayerInfo();
    public PlayerInfo greenBot = new PlayerInfo();
    public PlayerInfo orangeBot = new PlayerInfo();

    public SaveGameData(SaveFileManager saveMgr, HUBTracker tracker, InventoryManager manager)
    {
        //setting up file info----------------------------------------------------------------------------------------
        fileNameText = saveMgr.saveFileName;
        hours = saveMgr.hours;
        minutes = saveMgr.minutes;
        seconds = saveMgr.seconds;
        totalTimeInSeconds = saveMgr.totalTimeInSeconds;
        datumValue = manager.currency1;
        creditsValue = manager.currency;
        botLevelValue = saveMgr.botLevelValue;

        //setting up player info----------------------------------------------------------------------------------------
        for (int i = 0; i < 4; i++)
        {
            var currentStruct = new HUBTracker.botStruct();
            var currentBot = new PlayerInfo();

            if (i == 0)
            {
                currentStruct = tracker.leadBot;
                currentBot = leadBot;
            }
            else if (i == 1)
            {
                currentStruct = tracker.blueBot;
                currentBot = blueBot;
            }
            else if (i == 2)
            {
                currentStruct = tracker.greenBot;
                currentBot = greenBot;
            }
            else if (i == 3)
            {
                currentStruct = tracker.orangeBot;
                currentBot = orangeBot;
            }

            currentBot.points = currentStruct.points;
            currentBot.level = currentStruct.level;
            currentBot.exp = currentStruct.exp;
            currentBot.strength = currentStruct.strength;
            currentBot.electronics = currentStruct.electronics;
            currentBot.agility = currentStruct.agility;
            currentBot.combat = currentStruct.combat;
            currentBot.scanning = currentStruct.scanning;
            currentBot.efficiency = currentStruct.efficiency;
            currentBot.heavyHitter = currentStruct.heavyHitter;
            currentBot.retention = currentStruct.retention;
            currentBot.defender = currentStruct.defender;
            currentBot.objMaster = currentStruct.objMaster;
            currentBot.regenerator = currentStruct.regenerator;
            currentBot.lucky = currentStruct.lucky;
            currentBot.teamPlayer = currentStruct.teamPlayer;
            currentBot.informant = currentStruct.informant;
            currentBot.spec = currentStruct.spec;

            if (i == 0)
                leadBot = currentBot;
            else if (i == 1)
                blueBot = currentBot;
            else if (i == 2)
                greenBot = currentBot;
            else if (i == 3)
                orangeBot = currentBot;
        }

        //setting up inventory info----------------------------------------------------------------------------------------
        for (int i = 0; i < 5; i++)
        {
            List<GameObject> currentManagerList = new List<GameObject>();
            List<ItemInfo> currentInv = new List<ItemInfo>();

            currentInv.Clear();

            if (i == 0)
                currentManagerList = manager.leadEquipment;
            else if (i == 1)
                currentManagerList = manager.blueEquipment;
            else if (i == 2)
                currentManagerList = manager.greenEquipment;
            else if (i == 3)
                currentManagerList = manager.orangeEquipment;
            else if (i == 4)
                currentManagerList = manager.inventoryItems;

            if (currentManagerList.Count != 0)
            {
                for (int y = 0; y < currentManagerList.Count; y++) //for each item in the current list, set the item information
                {
                    Item currentItem = currentManagerList[y].GetComponent<Item>();

                    ItemInfo newItem = new ItemInfo
                    {
                        itemID = currentItem.itemStats.ID,
                        slotPosition = y,
                        equipped = currentItem.itemStats.equipped
                    };

                    if (currentItem.itemStats.leadOwns)
                        newItem.ownerID = 0;
                    else if (currentItem.itemStats.blueOwns)
                        newItem.ownerID = 1;
                    else if (currentItem.itemStats.greenOwns)
                        newItem.ownerID = 2;
                    if (currentItem.itemStats.orangeOwns)
                        newItem.ownerID = 3;

                    currentInv.Add(newItem);
                }
            }

            if (i == 0)
                leadEquipment = currentInv;
            else if (i == 1)
                blueEquipment = currentInv;
            else if (i == 2)
                greenEquipment = currentInv;
            else if (i == 3)
                orangeEquipment = currentInv;
            else if (i == 4)
                loadoutInventory = currentInv;
        }

        //setting up shop info-----------------------------------------------------------------------------------------
        armoryItemIDs = saveMgr.GetItemPoolArmoryInfo();
        junkItemIDs = saveMgr.GetItemPoolJunkInfo();
        weaponItemIDs = saveMgr.GetItemPoolWeaponInfo();
        specialItemIDs = saveMgr.GetItemPoolSpecialInfo();

        //setting up mission info--------------------------------------------------------------------------------------
        List<GameObject> missionsList = saveMgr.GetMissionsList();

        for (int i = 0; i < missionsList.Count; i++)
        {
            missionInfo newMission = new missionInfo();
            MissionSetup newMissionInfo = missionsList[i].GetComponent<MissionSetup>();

            newMission.missionName = newMissionInfo.GetMissionName();
            newMission.missionDesc = newMissionInfo.GetMissionDesc();
            newMission.factionName = newMissionInfo.GetFactionName();
            newMission.difficulty = newMissionInfo.GetDifficulty();
            newMission.rewards1 = newMissionInfo.GetReward1();
            newMission.rewards2 = newMissionInfo.GetReward2();

            missions.Add(newMission);
            Debug.Log("Added 1 new Mission. Total: " + missions.Count);
        }
    }
}