This commit is contained in:
2025-03-30 16:06:57 +02:00
parent e62bd2aa6d
commit 623ba3f621
148 changed files with 2773 additions and 1441 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 01849df87c1948778a9155b635cb0a8f
timeCreated: 1743252918

View File

@@ -0,0 +1,9 @@
using System.Threading;
using Cysharp.Threading.Tasks;
namespace RebootKit.Engine.UI {
public interface IView {
UniTask Show(CancellationToken cancellationToken);
UniTask Hide(CancellationToken cancellationToken);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fc4667c349ed4966bb7e16b7a790346e
timeCreated: 1743249178

View File

@@ -0,0 +1,90 @@
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UIElements;
namespace RebootKit.Engine.UI {
public static class Classes {
public const string k_Base = "rr__base";
public const string k_Label = "rr__label";
public const string k_Button = "rr__button";
}
public interface IVisualElementBuilder {
VisualElement Build();
}
public class VisualElementBuilder : IVisualElementBuilder {
readonly List<string> m_ClassNames = new();
Color? m_BackgroundColor;
float2? m_Size;
VisualElementBuilder() {
}
public VisualElementBuilder Class(string className) {
m_ClassNames.Add(className);
return this;
}
public VisualElementBuilder Class(params string[] classNames) {
foreach (string className in classNames) {
m_ClassNames.Add(className);
}
return this;
}
public VisualElementBuilder BackgroundColor(Color color) {
m_BackgroundColor = color;
return this;
}
public VisualElementBuilder Size(float2 size) {
m_Size = size;
return this;
}
public VisualElement Build() {
VisualElement element = new();
element.AddToClassList(Classes.k_Base);
foreach (string className in m_ClassNames) {
element.AddToClassList(className);
}
if (m_BackgroundColor.HasValue) {
element.style.backgroundColor = m_BackgroundColor.Value;
}
if (m_Size.HasValue) {
element.style.width = m_Size.Value.x;
element.style.height = m_Size.Value.y;
}
return element;
}
public static VisualElementBuilder New() {
return new VisualElementBuilder();
}
}
public readonly struct LabelBuilder : IVisualElementBuilder {
readonly string m_Text;
LabelBuilder(string text) {
m_Text = text;
}
public VisualElement Build() {
Label label = new(m_Text);
label.AddToClassList(Classes.k_Base);
label.AddToClassList(Classes.k_Label);
return label;
}
public static LabelBuilder New(string text) => new(text);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 17dda39a215248bba526d52f4d0886f3
timeCreated: 1743252930

View File

@@ -0,0 +1,38 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UIElements;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.UI {
public abstract class UIDocumentView : MonoBehaviour, IView, IVisualElementBuilder {
static readonly Logger s_logger = new(nameof(UIDocumentView));
[SerializeField] UIDocument m_Document;
void OnEnable() {
s_logger.Debug("START");
Rebuild();
}
public async UniTask Show(CancellationToken cancellationToken) {
await UniTask.Yield(cancellationToken);
}
public async UniTask Hide(CancellationToken cancellationToken) {
await UniTask.Yield(cancellationToken);
}
protected void Rebuild() {
Profiler.BeginSample("UI Tree Build");
VisualElement child = Build();
Profiler.EndSample();
m_Document.rootVisualElement.Q<VisualElement>("root__container").Clear();
m_Document.rootVisualElement.Q<VisualElement>("root__container").Add(child);
}
public abstract VisualElement Build();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5034480a2141411b96f6baffb6f7294c
timeCreated: 1743253410