using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class OVRLipSyncDebugConsole : MonoBehaviour
{
	public static OVRLipSyncDebugConsole instance
	{
		get
		{
			if (OVRLipSyncDebugConsole.s_Instance == null)
			{
				OVRLipSyncDebugConsole.s_Instance = (UnityEngine.Object.FindObjectOfType(typeof(OVRLipSyncDebugConsole)) as OVRLipSyncDebugConsole);
				if (OVRLipSyncDebugConsole.s_Instance == null)
				{
					GameObject gameObject = new GameObject();
					gameObject.AddComponent<OVRLipSyncDebugConsole>();
					gameObject.name = "OVRLipSyncDebugConsole";
					OVRLipSyncDebugConsole.s_Instance = (UnityEngine.Object.FindObjectOfType(typeof(OVRLipSyncDebugConsole)) as OVRLipSyncDebugConsole);
				}
			}
			return OVRLipSyncDebugConsole.s_Instance;
		}
	}

	private void Awake()
	{
		OVRLipSyncDebugConsole.s_Instance = this;
		this.Init();
	}

	private void Update()
	{
		if (this.clearTimeoutOn)
		{
			this.clearTimeout -= Time.deltaTime;
			if (this.clearTimeout < 0f)
			{
				OVRLipSyncDebugConsole.Clear();
				this.clearTimeout = 0f;
				this.clearTimeoutOn = false;
			}
		}
	}

	public void Init()
	{
		if (this.textMsg == null)
		{
			Debug.LogWarning("DebugConsole Init WARNING::UI text not set. Will not be able to display anything.");
		}
		OVRLipSyncDebugConsole.Clear();
	}

	public static void Log(string message)
	{
		OVRLipSyncDebugConsole.instance.AddMessage(message, Color.white);
	}

	public static void Log(string message, Color color)
	{
		OVRLipSyncDebugConsole.instance.AddMessage(message, color);
	}

	public static void Clear()
	{
		OVRLipSyncDebugConsole.instance.ClearMessages();
	}

	public static void ClearTimeout(float timeToClear)
	{
		OVRLipSyncDebugConsole.instance.SetClearTimeout(timeToClear);
	}

	public void AddMessage(string message, Color color)
	{
		this.messages.Add(message);
		if (this.textMsg != null)
		{
			this.textMsg.color = color;
		}
		this.Display();
	}

	public void ClearMessages()
	{
		this.messages.Clear();
		this.Display();
	}

	public void SetClearTimeout(float timeout)
	{
		this.clearTimeout = timeout;
		this.clearTimeoutOn = true;
	}

	private void Prune()
	{
		if (this.messages.Count > this.maxMessages)
		{
			int count;
			if (this.messages.Count <= 0)
			{
				count = 0;
			}
			else
			{
				count = this.messages.Count - this.maxMessages;
			}
			this.messages.RemoveRange(0, count);
		}
	}

	private void Display()
	{
		if (this.messages.Count > this.maxMessages)
		{
			this.Prune();
		}
		if (this.textMsg != null)
		{
			this.textMsg.text = string.Empty;
			for (int i = 0; i < this.messages.Count; i++)
			{
				Text text = this.textMsg;
				text.text += (string)this.messages[i];
				Text text2 = this.textMsg;
				text2.text += '\n';
			}
		}
	}

	public ArrayList messages = new ArrayList();

	public int maxMessages = 15;

	public Text textMsg;

	private static OVRLipSyncDebugConsole s_Instance;

	private bool clearTimeoutOn;

	private float clearTimeout;
}
