public static void GameObjectFromStream(Stream stream, GameObject into) { GameObjectSerializer.Read(stream, into); int numSavedComponents = stream.ReadInt(); for (int i = 0; i < numSavedComponents; i++) { var type = TypeSerializer.Read(stream); var component = into.GetOrAddComponent(type); ComponentFromStream(stream, type, component); } }
public static void GameObjectToStream(Stream stream, GameObject value, FSMarker marker) { GameObjectSerializer.Write(stream, value); var marked = marker.ComponentsToSave; stream.WriteInt(marked.Count); for (int i = 0; i < marked.Count; i++) { var type = marked[i]; var component = marker.GetComponent(type); TypeSerializer.Write(stream, component.GetType()); ComponentToStream(stream, type, component); } }
public static void GameObjectToStream(Stream stream, GameObject value) { var marker = value.GetComponent <FSMarker>(); if (marker != null) { GameObjectToStream(stream, value, marker); } else { GameObjectSerializer.Write(stream, value); var components = value.GetAllComponents(); stream.WriteInt(components.Length); for (int i = 0; i < components.Length; i++) { var component = components[i]; var type = component.GetType(); TypeSerializer.Write(stream, type); ComponentToStream(stream, type, component); } } }
public void SetLevel(GameObject level) { GameObjectSerializer gameObjectSerializer = new GameObjectSerializer(); levelData = gameObjectSerializer.ToSerializableGameObject(level); }