GesturePointOffset.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using Newtonsoft.Json;
  3. using System;
  4. /* GesturePointOffset 每一个定位点相对于上一个定位点的偏移量
  5. */
  6. public class GesturePointOffset
  7. {
  8. public float distance { set; get; } = 0f; // 两个点之间的距离
  9. public float angle { set; get; } = 0f;// 两个点之间的角度
  10. private DateTime time { set; get; }
  11. public GesturePointOffset(float distance, float angle)
  12. {
  13. this.distance = distance;
  14. this.angle = angle;
  15. time = DateTime.Now;
  16. }
  17. public string ExportToJson()
  18. {
  19. string json = JsonConvert.SerializeObject(this);
  20. return json;
  21. }
  22. public void ImportFromJson(string json)
  23. {
  24. var deserializedObject = JsonConvert.DeserializeObject<GesturePointOffset>(json);
  25. if (deserializedObject != null)
  26. {
  27. // 手动将反序列化后的对象的属性值复制到当前实例
  28. this.distance = deserializedObject.distance;
  29. this.angle = deserializedObject.angle;
  30. }
  31. }
  32. }