2020-07-30 20:27:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-02-15 19:59:18 +00:00
|
|
|
|
using System.Linq;
|
2020-07-30 20:27:14 +00:00
|
|
|
|
using OWML.Common;
|
2020-02-14 21:14:24 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2020-07-30 20:27:14 +00:00
|
|
|
|
namespace QSB.Utility
|
2020-02-15 19:48:02 +00:00
|
|
|
|
{
|
|
|
|
|
public class DebugLog : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private const int ScreenLinesMax = 6;
|
2020-02-14 21:14:24 +00:00
|
|
|
|
|
2020-02-15 19:48:02 +00:00
|
|
|
|
private static Text _screenText;
|
|
|
|
|
private static List<string> _lines;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
2020-02-14 21:14:24 +00:00
|
|
|
|
var assetBundle = QSB.Helper.Assets.LoadBundle("assets/debug");
|
2020-02-15 19:48:02 +00:00
|
|
|
|
var logCanvas = Instantiate(assetBundle.LoadAsset<GameObject>("assets/logcanvas.prefab"));
|
|
|
|
|
DontDestroyOnLoad(logCanvas);
|
2020-02-14 21:14:24 +00:00
|
|
|
|
DontDestroyOnLoad(this);
|
2020-02-15 19:48:02 +00:00
|
|
|
|
logCanvas.GetComponent<Canvas>().sortingOrder = 9999;
|
|
|
|
|
_screenText = logCanvas.GetComponentInChildren<Text>();
|
2020-02-14 21:14:24 +00:00
|
|
|
|
|
2020-02-15 19:48:02 +00:00
|
|
|
|
_lines = new List<string>(ScreenLinesMax);
|
|
|
|
|
for (var i = 0; i < ScreenLinesMax; i++)
|
|
|
|
|
{
|
2020-02-14 21:14:24 +00:00
|
|
|
|
_lines.Add(".");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 19:48:02 +00:00
|
|
|
|
private static string JoinAll(params object[] logObjects)
|
|
|
|
|
{
|
2020-02-15 19:59:18 +00:00
|
|
|
|
return string.Join(" ", logObjects.Select(o => o.ToString()).ToArray());
|
2020-02-14 21:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 23:13:43 +00:00
|
|
|
|
public static void ToConsole(string message)
|
2020-02-15 19:48:02 +00:00
|
|
|
|
{
|
2020-07-27 23:13:43 +00:00
|
|
|
|
QSB.Helper.Console.WriteLine(message, MessageType.Message);
|
2020-02-14 21:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 23:13:43 +00:00
|
|
|
|
public static void ToConsole(string message, MessageType type)
|
|
|
|
|
{
|
|
|
|
|
QSB.Helper.Console.WriteLine(message, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ToScreen(params object[] logObjects)
|
2020-02-15 19:48:02 +00:00
|
|
|
|
{
|
|
|
|
|
for (var i = 1; i < ScreenLinesMax; i++)
|
|
|
|
|
{
|
2020-02-14 21:14:24 +00:00
|
|
|
|
_lines[i - 1] = _lines[i];
|
|
|
|
|
}
|
2020-02-15 19:48:02 +00:00
|
|
|
|
_lines.Insert(ScreenLinesMax - 1, JoinAll(logObjects));
|
|
|
|
|
_screenText.text = string.Join("\n", _lines.ToArray());
|
2020-02-14 21:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 23:13:43 +00:00
|
|
|
|
public static void ToHud(params object[] logObjects)
|
2020-02-15 19:48:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (Locator.GetPlayerBody() == null)
|
|
|
|
|
{
|
2020-07-27 23:13:43 +00:00
|
|
|
|
//ToConsole("Warning: tried to log to HUD but player is not ready.");
|
|
|
|
|
//ToConsole("* " + JoinAll(logObjects));
|
2020-02-14 21:14:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-28 13:59:24 +00:00
|
|
|
|
var data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects));
|
|
|
|
|
NotificationManager.SharedInstance.PostNotification(data);
|
2020-02-14 21:14:24 +00:00
|
|
|
|
}
|
2020-02-15 19:48:02 +00:00
|
|
|
|
|
2020-07-27 23:13:43 +00:00
|
|
|
|
public static void ToAll(params object[] logObjects)
|
2020-03-04 20:46:16 +00:00
|
|
|
|
{
|
2020-07-27 23:13:43 +00:00
|
|
|
|
ToConsole(JoinAll(logObjects));
|
|
|
|
|
ToScreen(logObjects);
|
|
|
|
|
ToHud(logObjects);
|
2020-03-04 20:46:16 +00:00
|
|
|
|
}
|
2020-02-14 21:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|