-
Notifications
You must be signed in to change notification settings - Fork 0
/
Console.cs
67 lines (55 loc) · 2.39 KB
/
Console.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Pepperoni
{
internal class Console : MonoBehaviour
{
public static GameObject OverlayCanvas;
private static GameObject _textPanel;
public static Font Arial;
private const int LIST_LEN = 19;
private readonly List<string> _messages = new List<string>(LIST_LEN);
private bool _enabled = false;
public void Start()
{
Arial = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
DontDestroyOnLoad(gameObject);
if (OverlayCanvas == null)
{
CanvasUtil.CreateFonts();
OverlayCanvas = CanvasUtil.CreateCanvas(RenderMode.ScreenSpaceOverlay, new Vector2(1920, 1080));
OverlayCanvas.name = "ModdingApiConsoleLog";
DontDestroyOnLoad(OverlayCanvas);
GameObject background = CanvasUtil.CreateImagePanel(OverlayCanvas,
new Color32(0x28, 0x28, 0x28, 0xE8),
new CanvasUtil.RectData(new Vector2(0, 300), new Vector2(0, 0),
new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0)));
_textPanel = CanvasUtil.CreateTextPanel(background, string.Join(string.Empty, _messages.ToArray()), 12, TextAnchor.UpperLeft,
new CanvasUtil.RectData(new Vector2(-5, -5), new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 1)), Arial);
_textPanel.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Wrap;
OverlayCanvas.GetComponent<CanvasGroup>().alpha = 0;
}
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.F10))
{
StartCoroutine(_enabled
? CanvasUtil.FadeOutCanvasGroup(OverlayCanvas.GetComponent<CanvasGroup>())
: CanvasUtil.FadeInCanvasGroup(OverlayCanvas.GetComponent<CanvasGroup>()));
_enabled = !_enabled;
}
}
public void AddText(string message)
{
if (_messages.Count > LIST_LEN)
_messages.RemoveAt(0);
_messages.Add(message);
if (_textPanel != null)
{
_textPanel.GetComponent<Text>().text = string.Join(string.Empty, _messages.ToArray());
}
}
}
}