DragPointLightSerializer.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.IO;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class DragPointLightSerializer : Serializer<DragPointLight>
  5. {
  6. private const short version = 1;
  7. private static Serializer<LightProperty> LightPropertySerializer => Serialization.Get<LightProperty>();
  8. public override void Serialize(DragPointLight light, BinaryWriter writer)
  9. {
  10. writer.WriteVersion(version);
  11. LightProperty[] lightList = GetLightProperties(light);
  12. for (var i = 0; i < 3; i++) LightPropertySerializer.Serialize(lightList[i], writer);
  13. writer.Write(light.MyObject.position);
  14. writer.Write((int) light.SelectedLightType);
  15. writer.Write(light.IsColourMode);
  16. writer.Write(light.IsDisabled);
  17. }
  18. public override void Deserialize(DragPointLight light, BinaryReader reader, SceneMetadata metadata)
  19. {
  20. _ = reader.ReadVersion();
  21. LightProperty[] lightList = GetLightProperties(light);
  22. for (var i = 0; i < 3; i++) LightPropertySerializer.Deserialize(lightList[i], reader, metadata);
  23. light.MyObject.position = reader.ReadVector3();
  24. light.SetLightType((DragPointLight.MPSLightType) reader.ReadInt32());
  25. light.IsColourMode = reader.ReadBoolean();
  26. light.IsDisabled = reader.ReadBoolean();
  27. }
  28. private static LightProperty[] GetLightProperties(DragPointLight light)
  29. => Utility.GetFieldValue<DragPointLight, LightProperty[]>(light, "LightProperties");
  30. }
  31. }