BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / LipSync / Scripts / Helpers / OVRLipSyncDebugConsole.cs

OVRLipSyncDebugConsole.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
OVRLipSyncDebugConsole.cs 5.9 KiB Download Raw
1/************************************************************************************
2Filename : OVRLipSyncDebugConsole.cs
3Content : Write to a text string, used by UI.Text
4Created : May 22, 2015
5Copyright : Copyright Facebook Technologies, LLC and its affiliates.
6 All rights reserved.
7
8Licensed under the Oculus Audio SDK License Version 3.3 (the "License");
9you may not use the Oculus Audio SDK except in compliance with the License,
10which is provided at the time of installation or download, or which
11otherwise accompanies this software in either electronic or hard copy form.
12
13You may obtain a copy of the License at
14
15https://developer.oculus.com/licenses/audio-3.3/
16
17Unless required by applicable law or agreed to in writing, the Oculus Audio SDK
18distributed under the License is distributed on an "AS IS" BASIS,
19WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20See the License for the specific language governing permissions and
21limitations under the License.
22************************************************************************************/
23using UnityEngine;
24using UnityEngine.UI;
25using System.Collections;
26
27public class OVRLipSyncDebugConsole : MonoBehaviour
28{
29 public ArrayList messages = new ArrayList();
30 public int maxMessages = 15; // The max number of messages displayed
31 public Text textMsg; // text string to display
32
33 // Our instance to allow this script to be called without a direct connection.
34 private static OVRLipSyncDebugConsole s_Instance = null;
35
36 // Clear timeout
37 private bool clearTimeoutOn = false;
38 private float clearTimeout = 0.0f;
39
40 /// <summary>
41 /// Gets the instance.
42 /// </summary>
43 /// <value>The instance.</value>
44 public static OVRLipSyncDebugConsole instance
45 {
46 get
47 {
48 if (s_Instance == null)
49 {
50 s_Instance = FindObjectOfType(typeof(OVRLipSyncDebugConsole)) as OVRLipSyncDebugConsole;
51
52 if (s_Instance == null)
53 {
54 GameObject console = new GameObject();
55 console.AddComponent<OVRLipSyncDebugConsole>();
56 console.name = "OVRLipSyncDebugConsole";
57 s_Instance = FindObjectOfType(typeof(OVRLipSyncDebugConsole)) as OVRLipSyncDebugConsole;
58 }
59 }
60
61 return s_Instance;
62 }
63 }
64
65 /// <summary>
66 /// Awake this instance.
67 /// </summary>
68 void Awake()
69 {
70 s_Instance = this;
71 Init();
72
73 }
74
75 /// <summary>
76 /// Update this instance.
77 /// </summary>
78 void Update()
79 {
80 if(clearTimeoutOn == true)
81 {
82 clearTimeout -= Time.deltaTime;
83 if(clearTimeout < 0.0f)
84 {
85 Clear();
86 clearTimeout = 0.0f;
87 clearTimeoutOn = false;
88 }
89 }
90 }
91
92 /// <summary>
93 /// Init this instance.
94 /// </summary>
95 public void Init()
96 {
97 if(textMsg == null)
98 {
99 Debug.LogWarning("DebugConsole Init WARNING::UI text not set. Will not be able to display anything.");
100 }
101
102 Clear();
103 }
104
105
106 //+++++++++ INTERFACE FUNCTIONS ++++++++++++++++++++++++++++++++
107
108 /// <summary>
109 /// Log the specified message.
110 /// </summary>
111 /// <param name="message">Message.</param>
112 public static void Log(string message)
113 {
114 OVRLipSyncDebugConsole.instance.AddMessage(message, Color.white);
115 }
116
117 /// <summary>
118 /// Log the specified message and color.
119 /// </summary>
120 /// <param name="message">Message.</param>
121 /// <param name="color">Color.</param>
122 public static void Log(string message, Color color)
123 {
124 OVRLipSyncDebugConsole.instance.AddMessage(message, color);
125 }
126
127 /// <summary>
128 /// Clear this instance.
129 /// </summary>
130 public static void Clear()
131 {
132 OVRLipSyncDebugConsole.instance.ClearMessages();
133 }
134
135 /// <summary>
136 /// Calls clear after a certain time.
137 /// </summary>
138 /// <param name="timeToClear">Time to clear.</param>
139 public static void ClearTimeout(float timeToClear)
140 {
141 OVRLipSyncDebugConsole.instance.SetClearTimeout(timeToClear);
142 }
143
144 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
145
146
147 /// <summary>
148 /// Adds the message.
149 /// </summary>
150 /// <param name="message">Message.</param>
151 /// <param name="color">Color.</param>
152 public void AddMessage(string message, Color color)
153 {
154 messages.Add(message);
155
156 if(textMsg != null)
157 textMsg.color = color;
158
159 Display();
160 }
161
162 /// <summary>
163 /// Clears the messages.
164 /// </summary>
165 public void ClearMessages()
166 {
167 messages.Clear();
168 Display();
169 }
170
171 /// <summary>
172 /// Sets the clear timeout.
173 /// </summary>
174 /// <param name="timeout">Timeout.</param>
175 public void SetClearTimeout(float timeout)
176 {
177 clearTimeout = timeout;
178 clearTimeoutOn = true;
179 }
180
181 /// <summary>
182 // Prunes the array to fit within the maxMessages limit
183 /// </summary>
184 void Prune()
185 {
186 int diff;
187 if (messages.Count > maxMessages)
188 {
189 if (messages.Count <= 0)
190 {
191 diff = 0;
192 }
193 else
194 {
195 diff = messages.Count - maxMessages;
196 }
197 messages.RemoveRange(0, (int)diff);
198 }
199 }
200
201 /// <summary>
202 /// Display this instance.
203 /// </summary>
204 void Display()
205 {
206 if (messages.Count > maxMessages)
207 {
208 Prune();
209 }
210
211 if(textMsg != null)
212 {
213 textMsg.text = ""; // Clear text out
214 int x = 0;
215
216 while (x < messages.Count)
217 {
218 textMsg.text += (string)messages[x];
219 textMsg.text +='\n';
220 x += 1;
221 }
222 }
223 }
224}