Package a visible runtime UI theme
This commit is contained in:
parent
0947a8b753
commit
050b2019bd
9 changed files with 56 additions and 35 deletions
|
|
@ -252,18 +252,7 @@ namespace GameCult.Eve.UnityScene
|
|||
AttachToDocument();
|
||||
return;
|
||||
}
|
||||
_document = GetComponent<UIDocument>();
|
||||
if (_document == null)
|
||||
{
|
||||
var panel = ScriptableObject.CreateInstance<PanelSettings>();
|
||||
panel.name = "Eve playable-world HUD panel";
|
||||
panel.scaleMode = PanelScaleMode.ScaleWithScreenSize;
|
||||
panel.referenceResolution = new Vector2Int(1920, 1080);
|
||||
panel.match = 0.5f;
|
||||
_document = gameObject.AddComponent<UIDocument>();
|
||||
_document.panelSettings = panel;
|
||||
_document.sortingOrder = 100;
|
||||
}
|
||||
_document = EveUnityUiDocumentRuntime.Ensure(gameObject);
|
||||
_root = new VisualElement { name = "eve-input-action-bar" };
|
||||
_root.AddToClassList("eve-input-action-bar");
|
||||
_root.style.position = Position.Absolute;
|
||||
|
|
|
|||
|
|
@ -30,18 +30,7 @@ namespace GameCult.Eve.UnityScene
|
|||
AttachToDocument();
|
||||
return;
|
||||
}
|
||||
_document = GetComponent<UIDocument>();
|
||||
if (_document == null)
|
||||
{
|
||||
var panel = ScriptableObject.CreateInstance<PanelSettings>();
|
||||
panel.name = "Eve playable-world HUD panel";
|
||||
panel.scaleMode = PanelScaleMode.ScaleWithScreenSize;
|
||||
panel.referenceResolution = new Vector2Int(1920, 1080);
|
||||
panel.match = 0.5f;
|
||||
_document = gameObject.AddComponent<UIDocument>();
|
||||
_document.panelSettings = panel;
|
||||
_document.sortingOrder = 100;
|
||||
}
|
||||
_document = EveUnityUiDocumentRuntime.Ensure(gameObject);
|
||||
_root = new VisualElement();
|
||||
Build(_root);
|
||||
AttachToDocument();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Eve.UnityScene
|
||||
{
|
||||
internal static class EveUnityUiDocumentRuntime
|
||||
{
|
||||
private const string ThemeResource = "EveUnity/UnityDefaultRuntimeTheme";
|
||||
|
||||
public static UIDocument Ensure(GameObject host)
|
||||
{
|
||||
var document = host.GetComponent<UIDocument>();
|
||||
if (document != null) return document;
|
||||
|
||||
var theme = Resources.Load<ThemeStyleSheet>(ThemeResource);
|
||||
if (theme == null)
|
||||
throw new InvalidOperationException($"EveUnity runtime theme resource '{ThemeResource}' is missing.");
|
||||
|
||||
var panel = ScriptableObject.CreateInstance<PanelSettings>();
|
||||
panel.name = "Eve playable-world HUD panel";
|
||||
panel.scaleMode = PanelScaleMode.ScaleWithScreenSize;
|
||||
panel.referenceResolution = new Vector2Int(1920, 1080);
|
||||
panel.match = 0.5f;
|
||||
panel.themeStyleSheet = theme;
|
||||
|
||||
document = host.AddComponent<UIDocument>();
|
||||
document.panelSettings = panel;
|
||||
document.sortingOrder = 100;
|
||||
return document;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 894b54214cb34993a7984f73cb45349f
|
||||
|
|
@ -56,16 +56,7 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
private void EnsureDocument()
|
||||
{
|
||||
_document = GetComponent<UIDocument>();
|
||||
if (_document != null) return;
|
||||
var panel = ScriptableObject.CreateInstance<PanelSettings>();
|
||||
panel.name = "Eve playable-world surface panel";
|
||||
panel.scaleMode = PanelScaleMode.ScaleWithScreenSize;
|
||||
panel.referenceResolution = new Vector2Int(1920, 1080);
|
||||
panel.match = 0.5f;
|
||||
_document = gameObject.AddComponent<UIDocument>();
|
||||
_document.panelSettings = panel;
|
||||
_document.sortingOrder = 100;
|
||||
_document = EveUnityUiDocumentRuntime.Ensure(gameObject);
|
||||
}
|
||||
|
||||
private void AttachToDocument()
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
@import url("unity-theme://default");
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f30b970a2764f51ba064b032906259e
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0}
|
||||
disableValidation: 0
|
||||
unsupportedSelectorAction: 0
|
||||
|
|
@ -11,6 +11,7 @@ using NUnit.Framework;
|
|||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
#nullable enable
|
||||
|
||||
|
|
@ -1100,6 +1101,7 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
Assert.That(hostObject.GetComponent<EveUnityPlayableWorldCameraRig>(), Is.Not.Null);
|
||||
Assert.That(hostObject.GetComponent<EveUnityUiToolkitOverlay>(), Is.Not.Null);
|
||||
Assert.That(hostObject.GetComponent<EveUnityUiToolkitOverlay>().Root, Is.Not.Null);
|
||||
Assert.That(hostObject.GetComponent<UIDocument>().panelSettings.themeStyleSheet, Is.Not.Null);
|
||||
Assert.That(bootstrap.CameraTransform, Is.Not.Null);
|
||||
Assert.That(provider.RefreshCount, Is.EqualTo(1));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "org.gamecult.eve.unity-scene",
|
||||
"displayName": "Eve Unity Scene Lowering",
|
||||
"version": "0.3.102",
|
||||
"version": "0.3.103",
|
||||
"unity": "6000.0",
|
||||
"description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.",
|
||||
"dependencies": {
|
||||
|
|
|
|||
Reference in a new issue