DebugForDevice.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class DebugForDevice : MonoBehaviour
  7. {
  8. public static DebugForDevice ins;
  9. void Awake()
  10. {
  11. ins = this;
  12. }
  13. public void OnDataReceived(byte[] bytes) {
  14. if (bytes.Length != 27)
  15. {
  16. if (bytes.Length == 2)
  17. {
  18. Log("T1", "原始电量", string.Join(",", bytes));
  19. DeviceBatteryView.ins.RenderBattery(1, bytes[0]);
  20. return;
  21. }
  22. if (bytes.Length >= 3 && bytes[2] == 5)
  23. {
  24. long time = bytes[8] + (bytes[7] << 8) + (bytes[6] << 16) + (bytes[5] << 24);
  25. Log("T2", "原始遮挡", string.Join(",", bytes));
  26. Log("T3", "遮挡时间", time.ToString());
  27. try {
  28. ShootCheck.ins.webSocket.Send(time.ToString());
  29. } catch (Exception) {}
  30. }
  31. return;
  32. } else {
  33. Log("T", "原始九轴", string.Join(",", bytes));
  34. }
  35. }
  36. void Log(string nodeName, string title, string text) {
  37. this.transform.Find(nodeName).GetComponentInChildren<Text>().text = title + ": " + text;
  38. }
  39. }