added: debug overlay functional
This commit is contained in:
3
Assets/Core/UI/In-Game/Layouts/DebugOverlayRoot.uxml
Normal file
3
Assets/Core/UI/In-Game/Layouts/DebugOverlayRoot.uxml
Normal file
@@ -0,0 +1,3 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="StretchBG" style="width: 100%; height: 100%;" />
|
||||
</ui:UXML>
|
||||
10
Assets/Core/UI/In-Game/Layouts/DebugOverlayRoot.uxml.meta
Normal file
10
Assets/Core/UI/In-Game/Layouts/DebugOverlayRoot.uxml.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 639622e64fa8a624abe7cff26cb88fcb
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -0,0 +1,10 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="VisualElement">
|
||||
<ui:VisualElement style="flex-grow: 1; background-color: rgba(255, 144, 55, 0.47); border-top-left-radius: 2px; border-top-right-radius: 2px;">
|
||||
<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 style="background-color: rgba(202, 152, 104, 0.4);">
|
||||
<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;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ed11dc6647802148ba04f07e76c987f
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
7374
Assets/Scenes/DebugOverlay.unity
Normal file
7374
Assets/Scenes/DebugOverlay.unity
Normal file
File diff suppressed because one or more lines are too long
7
Assets/Scenes/DebugOverlay.unity.meta
Normal file
7
Assets/Scenes/DebugOverlay.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9803f648e57d84f45929c887da9d9435
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Core/Tools.meta
Normal file
8
Assets/Scripts/Core/Tools.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9ed10adc57e6b8489c6cad31b13a8aa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
97
Assets/Scripts/Core/Tools/DebugOverlayDrawer.cs
Normal file
97
Assets/Scripts/Core/Tools/DebugOverlayDrawer.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Reset.Core.Tools{
|
||||
public class DebugOverlayDrawer : MonoBehaviour{
|
||||
[ShowInInspector]
|
||||
public Dictionary<GameObject, List<string>> Pages = new(); // Page and value names
|
||||
[ShowInInspector]
|
||||
public Dictionary<object, Label> values = new(); // Value name and value value (lol)
|
||||
|
||||
public string pageNamePrefix = "Debug Page: ";
|
||||
|
||||
public VisualTreeAsset template;
|
||||
[ShowInInspector] public UIDocument root;
|
||||
public GameObject canvasRoot;
|
||||
|
||||
public GameObject currentPage;
|
||||
|
||||
|
||||
|
||||
public enum DebugOverlayAnchor{
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
Center
|
||||
}
|
||||
|
||||
void Awake(){
|
||||
if (Instance != null) {
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
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 thisPage = 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}") {
|
||||
thisPage = page.Key;
|
||||
alreadyExisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, this will make a new one and add it
|
||||
if (thisPage == null) {
|
||||
thisPage = new GameObject(name: $"{Instance.pageNamePrefix}{pageName}");
|
||||
Instance.Pages.Add(thisPage, new List<string>());
|
||||
thisPage.transform.SetParent(Instance.canvasRoot.transform);
|
||||
thisPage.AddComponent<UIDocument>();
|
||||
}
|
||||
|
||||
// Warning for the page being null for whatever reason
|
||||
if (thisPage == 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[thisPage].Contains(sourceName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Since it doesn't exist, add it to the list of tracked variables
|
||||
Instance.Pages[thisPage].Add(sourceName);
|
||||
|
||||
// Then create a new on-screen element for this variable
|
||||
VisualElement thisElement = (Instance.template.Instantiate());
|
||||
thisPage.GetComponent<UIDocument>().rootVisualElement.Add(thisElement);
|
||||
thisElement.style.alignSelf = new StyleEnum<Align>(Align.Center);
|
||||
|
||||
// Set it's label
|
||||
((Label)thisElement.Query<VisualElement>("Label").First()).text = sourceName;
|
||||
|
||||
|
||||
Instance.values.Add($"{pageName}/{sourceName}", (Label)thisElement.Query<VisualElement>("Value"));
|
||||
|
||||
}
|
||||
|
||||
public static void ChangeValue(string pageName, string sourceName, string newValue){
|
||||
Instance.values[$"{pageName}/{sourceName}"].text = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Core/Tools/DebugOverlayDrawer.cs.meta
Normal file
2
Assets/Scripts/Core/Tools/DebugOverlayDrawer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef2d32c8ac26b643851a4c8f18dacca
|
||||
10
Assets/Scripts/Core/Tools/DebugOverlayEntry.cs
Normal file
10
Assets/Scripts/Core/Tools/DebugOverlayEntry.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Core.Tools{
|
||||
public class DebugOverlayEntry{
|
||||
public string page;
|
||||
public string trackedName;
|
||||
public string trackedValue;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Tools/DebugOverlayEntry.cs.meta
Normal file
3
Assets/Scripts/Core/Tools/DebugOverlayEntry.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e168fc1f77fe443b97595b004e80af7e
|
||||
timeCreated: 1756152238
|
||||
Reference in New Issue
Block a user