Capture2D.cs 993 B

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. namespace Mirror.Examples.LagCompensationDemo
  3. {
  4. public struct Capture2D : Capture
  5. {
  6. public double timestamp { get; set; }
  7. public Vector2 position;
  8. public Vector2 size;
  9. public Capture2D(double timestamp, Vector2 position, Vector2 size)
  10. {
  11. this.timestamp = timestamp;
  12. this.position = position;
  13. this.size = size;
  14. }
  15. public void DrawGizmo()
  16. {
  17. Gizmos.DrawWireCube(position, size);
  18. }
  19. public static Capture2D Interpolate(Capture2D from, Capture2D to, double t) =>
  20. new Capture2D(
  21. 0, // interpolated snapshot is applied directly. don't need timestamps.
  22. Vector2.LerpUnclamped(from.position, to.position, (float)t),
  23. Vector2.LerpUnclamped(from.size, to.size, (float)t)
  24. );
  25. public override string ToString() => $"(time={timestamp} pos={position} size={size})";
  26. }
  27. }