DragPointPropDTOSerializer.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.IO;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class DragPointPropDTOSerializer : SimpleSerializer<DragPointPropDTO>
  5. {
  6. private const short version = 1;
  7. private static SimpleSerializer<PropInfo> PropInfoSerializer => Serialization.GetSimple<PropInfo>();
  8. private static SimpleSerializer<TransformDTO> TransformSerializer => Serialization.GetSimple<TransformDTO>();
  9. private static SimpleSerializer<AttachPointInfo> AttachPointSerializer
  10. => Serialization.GetSimple<AttachPointInfo>();
  11. public override void Serialize(DragPointPropDTO dragPointDto, BinaryWriter writer)
  12. {
  13. writer.WriteVersion(version);
  14. PropInfoSerializer.Serialize(dragPointDto.PropInfo, writer);
  15. TransformSerializer.Serialize(dragPointDto.TransformDTO, writer);
  16. AttachPointSerializer.Serialize(dragPointDto.AttachPointInfo, writer);
  17. writer.Write(dragPointDto.ShadowCasting);
  18. }
  19. public override DragPointPropDTO Deserialize(BinaryReader reader, SceneMetadata metadata)
  20. {
  21. _ = reader.ReadVersion();
  22. return new DragPointPropDTO
  23. {
  24. PropInfo = PropInfoSerializer.Deserialize(reader, metadata),
  25. TransformDTO = TransformSerializer.Deserialize(reader, metadata),
  26. AttachPointInfo = AttachPointSerializer.Deserialize(reader, metadata),
  27. ShadowCasting = reader.ReadBoolean()
  28. };
  29. }
  30. }
  31. public class DragPointPropDTO
  32. {
  33. public TransformDTO TransformDTO { get; init; }
  34. public AttachPointInfo AttachPointInfo { get; init; }
  35. public PropInfo PropInfo { get; init; }
  36. public bool ShadowCasting { get; init; }
  37. public DragPointPropDTO() { }
  38. public DragPointPropDTO(DragPointProp dragPoint)
  39. {
  40. TransformDTO = new TransformDTO(dragPoint.MyObject.transform);
  41. ShadowCasting = dragPoint.ShadowCasting;
  42. AttachPointInfo = dragPoint.AttachPointInfo;
  43. PropInfo = dragPoint.Info;
  44. }
  45. public void Deconstruct(out TransformDTO transform, out AttachPointInfo attachPointInfo, out bool shadowCasting)
  46. {
  47. transform = TransformDTO;
  48. attachPointInfo = AttachPointInfo;
  49. shadowCasting = ShadowCasting;
  50. }
  51. }
  52. }