OVRLipSyncDebugConsole.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class OVRLipSyncDebugConsole : MonoBehaviour
  6. {
  7. public static OVRLipSyncDebugConsole instance
  8. {
  9. get
  10. {
  11. if (OVRLipSyncDebugConsole.s_Instance == null)
  12. {
  13. OVRLipSyncDebugConsole.s_Instance = (UnityEngine.Object.FindObjectOfType(typeof(OVRLipSyncDebugConsole)) as OVRLipSyncDebugConsole);
  14. if (OVRLipSyncDebugConsole.s_Instance == null)
  15. {
  16. GameObject gameObject = new GameObject();
  17. gameObject.AddComponent<OVRLipSyncDebugConsole>();
  18. gameObject.name = "OVRLipSyncDebugConsole";
  19. OVRLipSyncDebugConsole.s_Instance = (UnityEngine.Object.FindObjectOfType(typeof(OVRLipSyncDebugConsole)) as OVRLipSyncDebugConsole);
  20. }
  21. }
  22. return OVRLipSyncDebugConsole.s_Instance;
  23. }
  24. }
  25. private void Awake()
  26. {
  27. OVRLipSyncDebugConsole.s_Instance = this;
  28. this.Init();
  29. }
  30. private void Update()
  31. {
  32. if (this.clearTimeoutOn)
  33. {
  34. this.clearTimeout -= Time.deltaTime;
  35. if (this.clearTimeout < 0f)
  36. {
  37. OVRLipSyncDebugConsole.Clear();
  38. this.clearTimeout = 0f;
  39. this.clearTimeoutOn = false;
  40. }
  41. }
  42. }
  43. public void Init()
  44. {
  45. if (this.textMsg == null)
  46. {
  47. Debug.LogWarning("DebugConsole Init WARNING::UI text not set. Will not be able to display anything.");
  48. }
  49. OVRLipSyncDebugConsole.Clear();
  50. }
  51. public static void Log(string message)
  52. {
  53. OVRLipSyncDebugConsole.instance.AddMessage(message, Color.white);
  54. }
  55. public static void Log(string message, Color color)
  56. {
  57. OVRLipSyncDebugConsole.instance.AddMessage(message, color);
  58. }
  59. public static void Clear()
  60. {
  61. OVRLipSyncDebugConsole.instance.ClearMessages();
  62. }
  63. public static void ClearTimeout(float timeToClear)
  64. {
  65. OVRLipSyncDebugConsole.instance.SetClearTimeout(timeToClear);
  66. }
  67. public void AddMessage(string message, Color color)
  68. {
  69. this.messages.Add(message);
  70. if (this.textMsg != null)
  71. {
  72. this.textMsg.color = color;
  73. }
  74. this.Display();
  75. }
  76. public void ClearMessages()
  77. {
  78. this.messages.Clear();
  79. this.Display();
  80. }
  81. public void SetClearTimeout(float timeout)
  82. {
  83. this.clearTimeout = timeout;
  84. this.clearTimeoutOn = true;
  85. }
  86. private void Prune()
  87. {
  88. if (this.messages.Count > this.maxMessages)
  89. {
  90. int count;
  91. if (this.messages.Count <= 0)
  92. {
  93. count = 0;
  94. }
  95. else
  96. {
  97. count = this.messages.Count - this.maxMessages;
  98. }
  99. this.messages.RemoveRange(0, count);
  100. }
  101. }
  102. private void Display()
  103. {
  104. if (this.messages.Count > this.maxMessages)
  105. {
  106. this.Prune();
  107. }
  108. if (this.textMsg != null)
  109. {
  110. this.textMsg.text = string.Empty;
  111. for (int i = 0; i < this.messages.Count; i++)
  112. {
  113. Text text = this.textMsg;
  114. text.text += (string)this.messages[i];
  115. Text text2 = this.textMsg;
  116. text2.text += '\n';
  117. }
  118. }
  119. }
  120. public ArrayList messages = new ArrayList();
  121. public int maxMessages = 15;
  122. public Text textMsg;
  123. private static OVRLipSyncDebugConsole s_Instance;
  124. private bool clearTimeoutOn;
  125. private float clearTimeout;
  126. }