GesturePointOffset.cs 967 B

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