Transform.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Island.StandardLib.Storage;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Island.StandardLib.Math
  7. {
  8. public class Transform : IStorable
  9. {
  10. Vector3 pos, fwd;
  11. public Vector3 position
  12. {
  13. get => pos; set
  14. {
  15. pos = value;
  16. OnChangePosition?.Invoke(pos);
  17. }
  18. }
  19. public Vector3 forward
  20. {
  21. get => fwd; set
  22. {
  23. fwd = value;
  24. OnChangeRotation?.Invoke(fwd);
  25. }
  26. }
  27. public Transform() { }
  28. readonly Action<Vector3> OnChangePosition;
  29. readonly Action<Vector3> OnChangeRotation;
  30. public Transform(Vector3 pos, Vector3 fwd, Action<Vector3> posChanged = null, Action<Vector3> rotChanged = null)
  31. {
  32. position = pos;
  33. forward = fwd;
  34. OnChangePosition = posChanged;
  35. OnChangeRotation = rotChanged;
  36. }
  37. public void WriteToData(DataStorage data)
  38. {
  39. data.Write(pos);
  40. data.Write(fwd);
  41. }
  42. public void ReadFromData(DataStorage data)
  43. {
  44. data.Read(out pos);
  45. data.Read(out fwd);
  46. }
  47. }
  48. }