5 Commits

Author SHA1 Message Date
Chris
acf2e23d71 feat: page locking, external page changing 2025-08-26 13:50:57 -04:00
Chris
b1b8a5b957 refactor: some coloring tweaks 2025-08-26 13:35:53 -04:00
Chris
4afb769d06 maint: removed unused file 2025-08-26 13:28:40 -04:00
Chris
a63f130e49 feat: controls for pages, better templates, color changing, clear commenting 2025-08-26 13:27:10 -04:00
Chris
0fad8c1416 added: debug overlay functional 2025-08-25 19:37:06 -04:00
14 changed files with 7703 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="SinglePage" style="background-color: rgba(204, 142, 84, 0.31); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border-left-color: rgba(255, 160, 61, 0.94); border-right-color: rgba(255, 160, 61, 0.94); border-top-color: rgba(255, 160, 61, 0.94); border-bottom-color: rgba(255, 160, 61, 0.94); border-top-width: 7px; border-right-width: 0.5px; border-bottom-width: 0.5px; border-left-width: 0.5px; width: auto; margin-right: 12px; max-width: 175px;">
<ui:Label text="Page Label" name="PageLabel" style="padding-right: 10px; padding-left: 10px; color: rgb(255, 255, 255); -unity-font-style: bold; padding-top: 10px; padding-bottom: 10px; flex-shrink: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 94d59802c4805cd44b4339b049e4ac06
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,3 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="ValuesContainer" style="flex-grow: 1; margin-top: 0; padding-top: 0; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; flex-shrink: 0;" />
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5bbda06c82d8c77478a2f5e7cc4e1f38
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,5 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="StretchBG" style="width: 100%; height: auto;">
<ui:VisualElement name="Pages" style="flex-direction: row; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 639622e64fa8a624abe7cff26cb88fcb
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,12 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement style="align-items: flex-start; margin-bottom: 10px;">
<ui:VisualElement name="VisualElement" style="max-width: 400px;">
<ui:VisualElement name="LabelBackground" style="background-color: rgba(255, 144, 55, 0.47); border-top-left-radius: 2px; border-top-right-radius: 2px; padding-right: 10px; padding-left: 10px;">
<ui:Label text="Label" name="Label" style="font-size: 15px; -unity-font-style: bold; color: rgb(255, 255, 255); padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 8px;" />
</ui:VisualElement>
<ui:VisualElement enabled="true" name="ValueBackground" style="background-color: rgba(202, 152, 104, 0.4); padding-left: 5px; padding-right: 5px;">
<ui:Label text="Label" name="Value" style="color: rgb(255, 255, 255); padding-left: 12px; padding-top: 2px; padding-bottom: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; flex-shrink: 1; width: 103px;" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2ed11dc6647802148ba04f07e76c987f
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -76,6 +76,33 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Debug Previous Page",
"type": "Button",
"id": "a41421f9-b1f7-458a-ba3b-a944f5d51822",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Debug Next Page",
"type": "Button",
"id": "38dbde33-5f5e-45d3-8bd2-0e4b5514ab26",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Debug Lock Page",
"type": "Button",
"id": "ad725c08-41d1-45b5-b5c9-3db391721b66",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
@@ -221,6 +248,105 @@
"action": "Stick",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "One Modifier",
"id": "c27cc4dc-9bef-427c-958c-5ce8fa9cb188",
"path": "OneModifier",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Previous Page",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "modifier",
"id": "2c93d991-353f-4e90-bda4-a4095009b19b",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Previous Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "binding",
"id": "de0fea7a-6ba2-46f9-92c0-a24da87da819",
"path": "<Gamepad>/leftShoulder",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Previous Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "One Modifier",
"id": "882c75bb-101d-4f31-8e34-f5b560d6e4ad",
"path": "OneModifier",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Next Page",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "modifier",
"id": "d3ff805f-9408-4e6a-b723-ccb3742757ac",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Next Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "binding",
"id": "0d619c6a-35b8-4184-9206-531c20e54c57",
"path": "<Gamepad>/rightShoulder",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Next Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "One Modifier",
"id": "e3076387-3607-4c5a-ac2d-11e2e03565b0",
"path": "OneModifier",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Lock Page",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "modifier",
"id": "aea9379f-fc0f-4ee8-affa-13b9f4cf1775",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Lock Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "Binding",
"id": "e9c97b2b-23b4-4cde-bfe2-451ddf093b27",
"path": "<Gamepad>/dpad/down",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Lock Page",
"isComposite": false,
"isPartOfComposite": true
}
]
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9803f648e57d84f45929c887da9d9435
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c9ed10adc57e6b8489c6cad31b13a8aa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
// ReSharper disable UsageOfDefaultStructEquality, to disable the warnings about IndexOf(currentPage). It's fine.
namespace Reset.Core.Tools{
public class DebugOverlayDrawer : MonoBehaviour{
[Header("Asset References")]
[BoxGroup("References")] public VisualTreeAsset valueTemplate;
[BoxGroup("References")] public VisualTreeAsset pageBaseTemplate;
[BoxGroup("References")] public VisualTreeAsset pageButtonTemplate;
[Header("Scene References")]
[BoxGroup("References")][ShowInInspector] public UIDocument root;
[BoxGroup("References")]public GameObject canvasRootGameObject;
[Space(10)]
[ShowInInspector]
public Dictionary<GameObject, List<string>> Pages = new(); // Page and value names
[Space(5)]
[ShowInInspector]
public Dictionary<object, Label> values = new(); // Value name and value value (lol)
[Space]
public string pageNamePrefix = "Debug Page: ";
public static bool Locked;
private static float defaultLabelAlpha;
private static float defaultValueAlpha;
// Private variables
[ShowInInspector]
public KeyValuePair<GameObject, List<string>> currentPage;
public enum DebugOverlayAnchor{
TopLeft,
TopRight,
BottomLeft,
BottomRight,
Center
}
void Awake(){
if (Instance != null) {
Destroy(this);
}
Instance = this;
}
void Start(){
SetCurrentPageVisible();
Debug.Log(valueTemplate.Instantiate().resolvedStyle.backgroundColor);
defaultLabelAlpha = valueTemplate.Instantiate().Query<VisualElement>("LabelBackground").First().resolvedStyle.backgroundColor.a;
defaultValueAlpha = valueTemplate.Instantiate().Query<VisualElement>("ValueBackground").First().resolvedStyle.backgroundColor.a;
}
public static DebugOverlayDrawer Instance;
public static void AddOnOverlay(string pageName, string sourceName, Vector3 position){
// Make sure the page exists. If it does, use it. If not, create it
GameObject thisPageObject = null;
bool alreadyExisted = false;
// This checks for a gameobject with the page name. Sets it if it finds it
foreach (var page in Instance.Pages) {
if (page.Key.name == $"{Instance.pageNamePrefix}{pageName}") {
thisPageObject = page.Key;
alreadyExisted = true;
break;
}
}
// Otherwise, this will make a new one and add it
UIDocument thisDocument;
if (thisPageObject == null) {
// Create a new object
thisPageObject = new GameObject(name: $"{Instance.pageNamePrefix}{pageName}");
// Add it to the list of page objects and set it's transform
KeyValuePair<GameObject, List<string>> newPage = new(thisPageObject, new List<string>());
Instance.Pages.Add(newPage.Key, newPage.Value);
thisPageObject.transform.SetParent(Instance.canvasRootGameObject.transform);
// Add a UI Document for it, give it the base template
thisDocument = thisPageObject.AddComponent<UIDocument>();
thisDocument.visualTreeAsset = Instance.pageBaseTemplate;
// Then add a button/header to the main container
VisualElement newPageButton = Instance.pageButtonTemplate.Instantiate();
Instance.root.rootVisualElement.Query<VisualElement>("Pages").First().Add(newPageButton);
((Label)newPageButton.Query<VisualElement>("PageLabel").First()).text = pageName;
} else {
thisDocument = thisPageObject.GetComponent<UIDocument>();
}
// If this is the only page, set it to the current page
if (Instance.Pages.Count == 1) {
ChangeToPage(pageName);
SetCurrentPageVisible();
}
// Warning for the page being null for whatever reason by this point
if (thisPageObject == null) {
Debug.LogError(
$"Debug Overlay Manager never found a page named: {sourceName}. It failed to create one and aborted.");
return;
}
// Now, iterate through this page and see if the variable is already tracked
if (alreadyExisted && Instance.Pages[thisPageObject].Contains(sourceName)) {
return;
}
// Since it doesn't exist, add it to the list of tracked variables
Instance.Pages[thisPageObject].Add(sourceName);
// Then create a new on-screen element for this variable
VisualElement thisElement = (Instance.valueTemplate.Instantiate());
thisDocument.rootVisualElement.Query<VisualElement>("ValuesContainer").First().Add(thisElement);
// Set it's label
((Label)thisElement.Query<VisualElement>("Label").First()).text = sourceName;
Instance.values.Add($"{pageName}/{sourceName}", (Label)thisElement.Query<VisualElement>("Value"));
}
// Publicly accessible method to change the value
public static void ChangeValue(string pageName, string sourceName, string newValue){
Instance.values[$"{pageName}/{sourceName}"].text = newValue;
}
// Publicly accessible method to change the color
public static void ChangeColor(string pageName, string sourceName, Color newColor){
VisualElement labelBG = Instance.values[$"{pageName}/{sourceName}"].parent.parent.Query<VisualElement>("LabelBackground").First();
VisualElement valueBG = Instance.values[$"{pageName}/{sourceName}"].parent.parent.Query<VisualElement>("ValueBackground").First();
labelBG.style.backgroundColor = ((newColor / 1.2f + Color.gray * .3f)* .7f).Alpha(defaultLabelAlpha);
valueBG.style.backgroundColor = ((newColor / 1.5f + Color.gray * .4f) * .6f) .Alpha(defaultValueAlpha);
}
// Change to a specific page
public static void ChangeToPage(string pageName){
if (Locked) {
Debug.LogWarning($"Can't switch to page {pageName}: Page is currently locked");
return;
}
try {
Instance.currentPage = Instance.Pages.Where(pair => pair.Key.name == Instance.pageNamePrefix + pageName).First();
} catch (Exception e) {
Debug.LogError($"Couldn't switch page to {pageName}: {e.Message}");
throw;
}
}
// Back a page
public static void PreviousPage(){
// Do nothing if there's only one page
if (Instance.Pages.Count == 1) {
return;
}
// Lock check
if (Locked) {
Debug.LogWarning($"Attempted to switch to a new page but the page is locked.");
return;
}
// Get the index of the current page
int currentIndex = Instance.Pages.ToList().IndexOf(Instance.currentPage);
// Change the page with wrapping
if (Instance.Pages.First().Key == Instance.currentPage.Key) {
Instance.currentPage = Instance.Pages.Last();
} else {
Instance.currentPage = Instance.Pages.ElementAt(currentIndex - 1);
}
// Set visibility
SetCurrentPageVisible();
}
public static void NextPage(){
// Do nothing if there's only one page
if (Instance.Pages.Count == 1) {
return;
}
// Lock check
if (Locked) {
Debug.LogWarning($"Attempted to switch to a new page but the page is locked.");
return;
}
// Get the index of the current page
int currentIndex = Instance.Pages.ToList().IndexOf(Instance.currentPage);
// Change the page with wrapping
if (Instance.Pages.Last().Key == Instance.currentPage.Key) {
Instance.currentPage = Instance.Pages.First();
} else {
Instance.currentPage = Instance.Pages.ElementAt(currentIndex + 1);
}
// Set visibility
SetCurrentPageVisible();
}
static void SetCurrentPageVisible(){
// Set the display property for the page to enable/disable them
foreach (var page in Instance.Pages) {
if (page.Key == Instance.currentPage.Key) {
page.Key.GetComponent<UIDocument>().rootVisualElement.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
} else {
page.Key.GetComponent<UIDocument>().rootVisualElement.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
}
// Turn all the page labels into a list
var pageButtons = Instance.root.rootVisualElement.Query<Label>("PageLabel").ToList();
// Iterate through said list and set the opacity of the parent (so everything including the label gets turned down)
foreach (Label page in pageButtons) {
page.parent.style.opacity = .4f;
if (Instance.currentPage.Key.name == $"{Instance.pageNamePrefix}{page.text}") {
page.parent.style.opacity = 1f;
}
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bef2d32c8ac26b643851a4c8f18dacca