- Home /
Serializing / deserializing large lists
I'm having trouble serializing / deserializing a large list I've created, and then saving / loading it when called for.
The list is for 50 characters, with over 15 individual values for each. The individual values can change (so sailor 36's wage could increase etc.) Rather than creating a thousand public variables and using a convoluted method of throwing the data about, I've tried to serialize the list and then save/load, but for the life of me, I can't figure it out.
I've been banging my head against a wall with this for days now, any help would be greatly appreciated.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Linq;
public class Stats : MonoBehaviour
{
public List<Sailor> sailors = new List<Sailor>();
public int selectedSailorIndex = 1;
public Text selectedSailorsTstat1;
void Start()
{
MakeSailorList();
}
public void MakeSailorList()
{
sailors.Add(new Sailor("ABRAHAM", "DIFFORD", 5, 20, 11, 15, 7, 9, 22, 30, 12, 6, 44, 12, 120, "IDLE", true));
sailors.Add(new Sailor("ABNER", "GOODING", 6, 14, 16, 20, 10, 10, 29, 13, 7, 51, 10, 9, 150, "IDLE", true));
// 50 sailors in total - etc...
}
public void Add_sTstat1()
{
sailors[selectedSailorIndex].sTstat1 += 1;
}
//more functions similair to this for rest of stats...
public void UpdateTextFields() {
selectedSailorsTstat1.text = sailors[selectedSailorIndex].sTstat1.ToString();
}
}
[Serializable()]
public class Sailor
{
public string sName1, sName2, sTask;
public int sTstat1, sFstat1, sHstat1, sSstat1, sTstat2, sFstat2, sHstat2, sSstat2, sTstat3, sFstat3, sHstat3, sSstat3, sWage;
public bool sAlive;
public Sailor(string newName1, string newName2, int newTstat1, int newFstat1, int newHstat1, int newSstat1, int newTstat2, int newFstat2, int newHstat2, int newSstat2, int newTstat3, int newFstat3, int newHstat3, int newSstat3, int newWage, string newTask, bool newAlive)
{
sName1 = newName1; sName2 = newName2; sTask = newTask; sWage = newWage; sAlive = newAlive;
sTstat1 = newTstat1; sFstat1 = newFstat1; sHstat1 = newHstat1; sSstat1 = newSstat1;
sTstat2 = newTstat2; sFstat2 = newFstat2; sHstat2 = newHstat2; sSstat2 = newSstat2;
sTstat3 = newTstat3; sFstat3 = newFstat3; sHstat3 = newHstat3; sSstat3 = newSstat3;
}
}
Your answer
Follow this Question
Related Questions
Save/Load Animation State of Instantiated Prefabs 0 Answers
Serialization Location 1 Answer
Serializing a graph 2 Answers
Importing and exporting save files. 0 Answers
how to properly save an int value ? 2 Answers