DebugDeviceCMD.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class DebugDeviceCMD : MonoBehaviour
  6. {
  7. public static DebugDeviceCMD ins;
  8. Transform textGroup;
  9. string[] textStrList;
  10. int index = 0;
  11. void Awake() {
  12. if (ins) {
  13. Destroy(this.gameObject);
  14. return;
  15. }
  16. ins = this;
  17. DontDestroyOnLoad(this.gameObject);
  18. textGroup = transform.Find("TextGroup");
  19. textStrList = new string[textGroup.childCount];
  20. for (int i = 0; i < textStrList.Length; i++) {
  21. textStrList[i] = "";
  22. }
  23. }
  24. public void ShowCMD(string cmd) {
  25. string str = $"序号{index}: {cmd}";
  26. index++;
  27. if (index < textStrList.Length) {
  28. textStrList[index] = str;
  29. } else {
  30. System.Array.Copy(textStrList, 1, textStrList, 0, textStrList.Length - 1);
  31. textStrList[textStrList.Length - 1] = str;
  32. }
  33. for (int i = 0; i < textStrList.Length; i++) {
  34. textGroup.GetChild(i).GetComponent<Text>().text = textStrList[i];
  35. }
  36. }
  37. // float t = 0;
  38. // void Update() {
  39. // t += Time.deltaTime;
  40. // if (t > 0.1f) {
  41. // t = 0;
  42. // ShowCMD("A" + index);
  43. // }
  44. // }
  45. }