38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
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();
|
|
}
|
|
} |