DebugForDevice.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. if (ins) {
  12. Destroy(this.gameObject);
  13. } else {
  14. ins = this;
  15. DontDestroyOnLoad(this.gameObject);
  16. }
  17. }
  18. int tid = 0;
  19. string[] logs = new string[3];
  20. public void LogInfrared(byte[] bytes, string info) {
  21. tid++;
  22. string bytesLog = string.Join(", ", bytes);
  23. string text = $"第{tid}波信息\n原始数据:{bytesLog}\n{info}\n\n";
  24. if (tid <= logs.Length) {
  25. logs[tid - 1] = text;
  26. } else {
  27. for (int i = 0; i < logs.Length - 1; i++) {
  28. logs[i] = logs[i + 1];
  29. }
  30. logs[logs.Length - 1] = text;
  31. }
  32. string logInfo = "";
  33. for (int i = 0; i < tid && i < logs.Length; i++) {
  34. logInfo += logs[i];
  35. }
  36. this.transform.Find("T").GetComponentInChildren<Text>().text = logInfo;
  37. }
  38. }