LightManagerSerializer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class LightManagerSerializer : Serializer<LightManager>
  6. {
  7. private const short version = 1;
  8. private static Serializer<DragPointLight> LightSerializer => Serialization.Get<DragPointLight>();
  9. public override void Serialize(LightManager manager, BinaryWriter writer)
  10. {
  11. writer.Write(LightManager.header);
  12. writer.WriteVersion(version);
  13. List<DragPointLight> list = GetLightList(manager);
  14. writer.Write(list.Count);
  15. foreach (var light in list) LightSerializer.Serialize(light, writer);
  16. }
  17. public override void Deserialize(LightManager manager, BinaryReader reader, SceneMetadata metadata)
  18. {
  19. manager.ClearLights();
  20. _ = reader.ReadVersion();
  21. var lightCount = reader.ReadInt32();
  22. List<DragPointLight> list = GetLightList(manager);
  23. LightSerializer.Deserialize(list[0], reader, metadata);
  24. for (var i = 1; i < lightCount; i++)
  25. {
  26. manager.AddLight();
  27. LightSerializer.Deserialize(list[i], reader, metadata);
  28. }
  29. }
  30. private static List<DragPointLight> GetLightList(LightManager manager)
  31. => Utility.GetFieldValue<LightManager, List<DragPointLight>>(manager, "lightList");
  32. }
  33. }