VisualLogger.cs 757 Bytes
using LAViD.Unity.Utils;
using System.Collections.Generic;
using UnityEngine.UI;

namespace LAViD.VLibras.Utils {

	public class VisualLogger : PlayerLogger {

		private Text textObj;
		public int maximumLines = 20;

		private List<string> logs = new List<string>();
		private bool logged = false;

		protected override void Start()
		{
			base.Start();
			this.textObj = this.gameObject.GetComponent<Text>();
		}

		protected override void write(string text)
		{
			this.logs.Insert(0, text);

			if (this.logs.Count > this.maximumLines)
				this.logs.RemoveAt(this.logs.Count - 1);

			logged = true;
		}

		public void Update()
		{
			if (logged)
			{
				logged = false;
				this.textObj.text = string.Join("\n", this.logs.ToArray());
			}
		}

	}

}