Hey there,
I’m having trouble with saving and loading nested objects. I have a scene object like this:
[Serializable]
public class SS_SceneObject
{
public string SceneName;
public int SceneID;
public List<O_Object> O_ObjectList = new List<O_Object>();
}
The scene holds 'O_Object’s within a list. I’m wondering if I should be serializing the O_Objects here:
public class SS_O_Object
{
public GameObject O_Object_gameObject;
public O_Lists.TriggerType triggerType;
public List<string> O_List;
public Vector3 storedPosition;
public Vector3 storedRotation;
public enum Control { Controlled, NotControlled }
public Control control;
public int O_Interpreter_CurIndex;
public Vector3 O_memorizedLocalRotation;
}
The code I’m using to either write or to read from a file isn’t working, and it’s very hard to debug right now as there’s no way to just check if the data wrote to the file or not…
I don’t really care that the file is in binary. I’m using the following type of code for opening:
//Create scene object
SS_SceneObject sceneObject = new SS_SceneObject ();
//Open file
BinaryFormatter binaryFormatter = new BinaryFormatter ();
FileStream fileStream = File.Open (Application.dataPath + "/Maps/Map" + sceneID + ".map", FileMode.Open);
//Write to scene object
sceneObject = (SS_SceneObject)binaryFormatter.Deserialize (fileStream);
//Close file
fileStream.Close ();
I’m considering using XML or JSON files instead. Isn’t there a way to just write the file straight to a text file without converting it to binary, so that I can debug it more easily?