mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
feat: made a debug menu component
This commit is contained in:
parent
2ecad16acc
commit
26f24250fa
74
NewHorizons/Utility/DebugMenu.cs
Normal file
74
NewHorizons/Utility/DebugMenu.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
|
namespace NewHorizons.Utility
|
||||||
|
{
|
||||||
|
class DebugMenu : MonoBehaviour
|
||||||
|
{
|
||||||
|
GUIStyle _editorMenuStyle;
|
||||||
|
Vector2 EditorMenuSize = new Vector2(600, 900);
|
||||||
|
bool menuOpen = false;
|
||||||
|
|
||||||
|
private void InitMenu()
|
||||||
|
{
|
||||||
|
if (_editorMenuStyle != null) return;
|
||||||
|
|
||||||
|
Texture2D bgTexture = MakeTexture((int)EditorMenuSize.x, (int)EditorMenuSize.y, Color.black);
|
||||||
|
|
||||||
|
_editorMenuStyle = new GUIStyle
|
||||||
|
{
|
||||||
|
normal =
|
||||||
|
{
|
||||||
|
background = bgTexture
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Texture2D MakeTexture(int width, int height, Color color)
|
||||||
|
{
|
||||||
|
Color[] pixels = new Color[width*height];
|
||||||
|
|
||||||
|
for(int i = 0; i < pixels.Length; i++)
|
||||||
|
{
|
||||||
|
pixels[i] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D newTexture = new Texture2D(width, height);
|
||||||
|
newTexture.SetPixels(pixels);
|
||||||
|
newTexture.Apply();
|
||||||
|
return newTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGUI()
|
||||||
|
{
|
||||||
|
if (!menuOpen) return;
|
||||||
|
if (!Main.Debug) return;
|
||||||
|
|
||||||
|
Vector2 menuPosition = Vector2.zero; // new Vector2(Screen.width - EditorMenuSize.x - 10, 10);
|
||||||
|
|
||||||
|
//TODO: add gui for stuff https://github.com/Bwc9876/OW-SaveEditor/blob/master/SaveEditor/SaveEditor.cs
|
||||||
|
// https://docs.unity3d.com/ScriptReference/GUI.TextField.html
|
||||||
|
GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle);
|
||||||
|
GUILayout.Label("*: Restart Required");
|
||||||
|
GUILayout.Space(20);
|
||||||
|
GUILayout.Label("*: Restart Required");
|
||||||
|
GUILayout.EndArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (!Main.Debug) return;
|
||||||
|
|
||||||
|
if (Keyboard.current[Key.Escape].wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
menuOpen = !menuOpen;
|
||||||
|
if (menuOpen) InitMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user