- Delete `TestScript` and associated components no longer in use. - Refactor `DebugUi` with a generalized labeling system to streamline UI updates and scalability. - Replace inline UI styles in `UI Document` with external USS file for cleaner and maintainable styling. - Update `SampleScene` configurations to align with these changes and remove redundant object references.
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class DebugUi : MonoBehaviour
|
|
{
|
|
private UIDocument _uiDocument;
|
|
|
|
private readonly Dictionary<string, string> _labels = new();
|
|
|
|
private VisualElement _container;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_uiDocument = GetComponent<UIDocument>();
|
|
_container = _uiDocument.rootVisualElement.Q<VisualElement>("labelsContainer");
|
|
}
|
|
|
|
public void UpdateText(string key, string value)
|
|
{
|
|
_labels[key] = value;
|
|
|
|
UpdateLabels();
|
|
}
|
|
|
|
private void UpdateLabels()
|
|
{
|
|
_container.Clear();
|
|
|
|
foreach (var keyValuePair in _labels) {
|
|
|
|
var parent = new VisualElement();
|
|
parent.AddToClassList("labelContainer");
|
|
|
|
var keyLabel = new Label(keyValuePair.Key);
|
|
keyLabel.AddToClassList("label");
|
|
parent.Add(keyLabel);
|
|
|
|
var valueLabel = new Label(keyValuePair.Value);
|
|
valueLabel.AddToClassList("label");
|
|
parent.Add(valueLabel);
|
|
|
|
_container.Add(parent);
|
|
}
|
|
}
|
|
} |