So i’m trying to make this dictionary survive recompiles, but i don’t know how.
public class HexGraph : MonoBehaviour {
public Dictionary<HexCell, List<Edge>> edges = new
Dictionary<HexCell, List<Edge>>();
}
Here is the Edge struct, if that makes a difference.
public struct Edge : IComparable<Edge> {
public int CompareTo (Edge other) {
return cost.CompareTo(other.cost);
}
public HexCell connection;
public float cost;
public Edge (HexCell connection, float cost) {
this.connection = connection;
this.cost = cost;
}
}
EDIT
So i tried what RobAnthem suggested, but couldn’t make it work, so instead i updated my dictionary OnEnable()
I’m still marking his answer as correct, because i’m sure it was my fault it didn’t work.
Basic binary serialization
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("edges.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, edges);
stream.Close();
Basic binary deserialization
FileStream fs = new FileStream("edges.bin", FileMode.Open);
IFormatter formatter = new BinaryFormatter();
edges = (Dictionary<HexCell, List<Edge>>)formatter.Deserialize(fs);
fs.Close();