AOTAdapter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.Scripting;
  5. using o0.Num;
  6. using o0.Geometry;
  7. //AOT适配器[#该脚本非常重要不要删除#]
  8. //该脚本需要挂载在场景中才会生效,只要静态构造函数得以调用就ok了
  9. [Preserve]
  10. public class AOTAdapter : MonoBehaviour
  11. {
  12. static AOTAdapter()
  13. {
  14. //o0.Num泛型类的显式创建
  15. Num<Vector<double>>.Plus = (a, b) => a + b;
  16. Num<Vector<double>>.Minus = (a, b) => a - b;
  17. Num<Vector<double>>.Multiply = (a, b) => a * b;
  18. Num<Vector<double>>.Divide = (a, b) => a / b;
  19. Num<Vector<double>>.Rate = (a, b) => a * b;
  20. }
  21. //用保存的模块数据片段,测试陀螺仪校准,排查aot编译导致底层函数出错
  22. IEnumerator TestCalibrateGyrBy9AxisData() {
  23. while (!AimHandler.ins) yield return null;
  24. Debug.Log("start-Test9AxisData");
  25. AimHandler.ins.CalibrateGyr(true);
  26. string dataText = Resources.Load<TextAsset>("test-data").text;
  27. int a = 0;
  28. foreach (var dataLine in dataText.Split('\n'))
  29. {
  30. AimHandler.ins.OnDataReceived(ToBytes(dataLine));
  31. a++;
  32. if (a == 100) AimHandler.ins.CalibrateGyr(false);
  33. }
  34. Debug.Log("end-Test9AxisData");
  35. }
  36. byte[] ToBytes(string msg) {
  37. return Array.ConvertAll<string, byte>(msg.Split(','), s => byte.Parse(s));
  38. }
  39. }