-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
* Create global UIDocument for scenes UI + start implementing UIText systems * Fix IntegrationTestsSuite * Move SceneUI folder to DCL/SDKComponents * Handle UIText removal * Update SceneUIPlugin.cs * Update UITextHandlerSystem.cs * Setup canvas with the default configuration * Move ProtoConvertUtils and UiElementUtils under SceneUI folder * Implement UITransform * Create a style sheet for the main canvas * Update UITransformHandlerSystem.cs * Fix tests * Move the release logic to separated systems * Make UITransformInstantiationSystem executes first of all the rest of systems * Apply parenting to UIText * Set a name for each component * UITransform: parenting and sorting * Add an option to clear PB components on Get * Set default values in UiElementUtils.SetupVisualElement function * Implement detection of the current scene * Hide scene UI when we're out of the scene * UIText test coverage * Reset processed parcel on realm invalidation * UITransformInstantiation test coverage * UITransformUpdate test coverage * Apply feedback: Add maxSize to AddComponentPool method * Fix code conventions tests * Fix async tests * Upgrade TestFramework to 1.4.2 * Async Setup/Teardown issue fixed * More stable --------- Co-authored-by: Mikhail Agapov <[email protected]>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using UnityEngine.AddressableAssets; | ||
using UnityEngine.UIElements; | ||
|
||
namespace DCL.AssetsProvision | ||
{ | ||
[Serializable] | ||
public class AssetReferenceStyleSheet : AssetReferenceT<StyleSheet> | ||
{ | ||
public AssetReferenceStyleSheet(string guid) : base(guid) { } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using UnityEngine.UIElements; | ||
|
||
namespace DCL.AssetsProvision | ||
{ | ||
[Serializable] | ||
public class UIDocumentRef : ComponentReference<UIDocument> | ||
{ | ||
public UIDocumentRef(string guid) : base(guid) { } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Arch.SystemGroups; | ||
using Cysharp.Threading.Tasks; | ||
using DCL.AssetsProvision; | ||
using DCL.Optimization.Pools; | ||
using DCL.PluginSystem.World.Dependencies; | ||
using DCL.SDKComponents.SceneUI.Components; | ||
using DCL.SDKComponents.SceneUI.Utils; | ||
using ECS.ComponentsPooling.Systems; | ||
using ECS.LifeCycle; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
using UITextInstantiationSystem = DCL.SDKComponents.SceneUI.Systems.UIText.UITextInstantiationSystem; | ||
using UITextReleaseSystem = DCL.SDKComponents.SceneUI.Systems.UIText.UITextReleaseSystem; | ||
using UITransformInstantiationSystem = DCL.SDKComponents.SceneUI.Systems.UITransform.UITransformInstantiationSystem; | ||
using UITransformParentingSystem = DCL.SDKComponents.SceneUI.Systems.UITransform.UITransformParentingSystem; | ||
using UITransformReleaseSystem = DCL.SDKComponents.SceneUI.Systems.UITransform.UITransformReleaseSystem; | ||
using UITransformSortingSystem = DCL.SDKComponents.SceneUI.Systems.UITransform.UITransformSortingSystem; | ||
using UITransformUpdateSystem = DCL.SDKComponents.SceneUI.Systems.UITransform.UITransformUpdateSystem; | ||
|
||
namespace DCL.PluginSystem.World | ||
{ | ||
public class SceneUIPlugin : IDCLWorldPlugin<SceneUIPlugin.Settings> | ||
{ | ||
private UIDocument canvas; | ||
|
||
private readonly IComponentPoolsRegistry componentPoolsRegistry; | ||
private readonly IAssetsProvisioner assetsProvisioner; | ||
|
||
public SceneUIPlugin(ECSWorldSingletonSharedDependencies singletonSharedDependencies, IAssetsProvisioner assetsProvisioner) | ||
{ | ||
this.assetsProvisioner = assetsProvisioner; | ||
componentPoolsRegistry = singletonSharedDependencies.ComponentPoolsRegistry; | ||
componentPoolsRegistry.AddComponentPool<VisualElement>(onRelease: UiElementUtils.ReleaseUIElement, maxSize: 200); | ||
componentPoolsRegistry.AddComponentPool<Label>(onRelease: UiElementUtils.ReleaseUIElement, maxSize: 100); | ||
} | ||
|
||
public async UniTask InitializeAsync(Settings settings, CancellationToken ct) | ||
{ | ||
canvas = (await assetsProvisioner.ProvideInstanceAsync(settings.Canvas, ct: ct)).Value; | ||
StyleSheet scenesUIStyleSheet = (await assetsProvisioner.ProvideMainAssetAsync(settings.StyleSheet, ct)).Value; | ||
|
||
canvas.rootVisualElement.styleSheets.Add(scenesUIStyleSheet); | ||
canvas.rootVisualElement.AddToClassList("sceneUIMainCanvas"); | ||
canvas.rootVisualElement.pickingMode = PickingMode.Ignore; | ||
} | ||
|
||
public void InjectToWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder, in ECSWorldInstanceSharedDependencies sharedDependencies, in PersistentEntities persistentEntities, List<IFinalizeWorldSystem> finalizeWorldSystems) | ||
{ | ||
UITransformInstantiationSystem.InjectToWorld(ref builder, canvas, componentPoolsRegistry); | ||
UITransformParentingSystem.InjectToWorld(ref builder, sharedDependencies.EntitiesMap, persistentEntities.SceneRoot); | ||
UITransformSortingSystem.InjectToWorld(ref builder, sharedDependencies.EntitiesMap, persistentEntities.SceneRoot); | ||
UITransformUpdateSystem.InjectToWorld(ref builder, canvas, sharedDependencies.SceneStateProvider); | ||
UITransformReleaseSystem.InjectToWorld(ref builder, componentPoolsRegistry); | ||
UITextInstantiationSystem.InjectToWorld(ref builder, componentPoolsRegistry); | ||
UITextReleaseSystem.InjectToWorld(ref builder, componentPoolsRegistry); | ||
|
||
finalizeWorldSystems.Add(ReleasePoolableComponentSystem<VisualElement, UITransformComponent>.InjectToWorld(ref builder, componentPoolsRegistry)); | ||
finalizeWorldSystems.Add(ReleasePoolableComponentSystem<Label, UITextComponent>.InjectToWorld(ref builder, componentPoolsRegistry)); | ||
} | ||
|
||
public void InjectToEmptySceneWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder, in EmptyScenesWorldSharedDependencies dependencies) { } | ||
|
||
public void Dispose() { } | ||
|
||
[Serializable] | ||
public class Settings : IDCLPluginSettings | ||
{ | ||
[field: Header(nameof(SceneUIPlugin) + "." + nameof(Settings))] | ||
[field: Space] | ||
[field: SerializeField] | ||
public UIDocumentRef Canvas { get; private set; } = null!; | ||
|
||
[field: SerializeField] | ||
public AssetReferenceStyleSheet StyleSheet { get; private set; } = null!; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using DCL.Optimization.Pools; | ||
using System; | ||
using UnityEngine.UIElements; | ||
|
||
namespace DCL.SDKComponents.SceneUI.Components | ||
{ | ||
public struct UITextComponent: IPoolableComponentProvider<Label> | ||
{ | ||
public Label Label; | ||
|
||
Label IPoolableComponentProvider<Label>.PoolableComponent => Label; | ||
Type IPoolableComponentProvider<Label>.PoolableComponentType => typeof(Label); | ||
|
||
public void Dispose() { } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Arch.Core; | ||
using DCL.Optimization.Pools; | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine.Pool; | ||
using UnityEngine.UIElements; | ||
|
||
namespace DCL.SDKComponents.SceneUI.Components | ||
{ | ||
public struct UITransformComponent : IPoolableComponentProvider<VisualElement> | ||
{ | ||
public VisualElement Transform; | ||
public EntityReference Parent; | ||
public HashSet<EntityReference> Children; | ||
public bool IsHidden; | ||
|
||
VisualElement IPoolableComponentProvider<VisualElement>.PoolableComponent => Transform; | ||
Type IPoolableComponentProvider<VisualElement>.PoolableComponentType => typeof(VisualElement); | ||
|
||
public void Dispose() | ||
{ | ||
HashSetPool<EntityReference>.Release(Children); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using DCL.ECSComponents; | ||
using DCL.SDKComponents.SceneUI.Utils; | ||
using ECS.Unity.ColorComponent; | ||
using UnityEngine; | ||
using Font = DCL.ECSComponents.Font; | ||
|
||
namespace DCL.SDKComponents.SceneUI.Defaults | ||
{ | ||
public static class PBUiTextDefaults | ||
{ | ||
public static Color GetColor(this PBUiText self) => | ||
self.Color?.ToUnityColor() ?? ColorDefaults.COLOR_WHITE; | ||
|
||
public static TextAnchor GetTextAlign(this PBUiText self) => | ||
(self.HasTextAlign ? self.TextAlign : TextAlignMode.TamMiddleCenter).ToUnityTextAlign(); | ||
|
||
public static Font GetFont(this PBUiText self) => | ||
self.HasFont ? self.Font : Font.FSansSerif; | ||
|
||
public static float GetFontSize(this PBUiText self) => | ||
self.HasFontSize ? self.FontSize : 10; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using DCL.ECSComponents; | ||
|
||
namespace DCL.SDKComponents.SceneUI.Defaults | ||
{ | ||
public static class PBUiTransform_Defaults | ||
{ | ||
public static float GetFlexShrink(this PBUiTransform self) => | ||
self.HasFlexShrink ? self.FlexShrink : 1; | ||
|
||
public static YGAlign GetAlignItems(this PBUiTransform self) => | ||
self.HasAlignItems ? self.AlignItems : YGAlign.YgaStretch; | ||
|
||
public static YGAlign GetAlignContent(this PBUiTransform self) => | ||
self.HasAlignContent ? self.AlignContent : YGAlign.YgaStretch; | ||
|
||
public static YGWrap GetFlexWrap(this PBUiTransform self) => | ||
self.HasFlexWrap ? self.FlexWrap : YGWrap.YgwNoWrap; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Arch.SystemGroups; | ||
using Arch.SystemGroups.Throttling; | ||
using DCL.SDKComponents.SceneUI.Systems; | ||
using ECS.Groups; | ||
using UITransformInstantiationSystem = DCL.SDKComponents.SceneUI.Systems.UITransform.UITransformInstantiationSystem; | ||
|
||
namespace DCL.SDKComponents.SceneUI.Groups | ||
{ | ||
/// <summary> | ||
/// Denotes the group that instantiates specific components right after the entity transform is handled | ||
/// </summary> | ||
[UpdateInGroup(typeof(SyncedSimulationSystemGroup))] | ||
[UpdateAfter(typeof(UITransformInstantiationSystem))] | ||
[ThrottlingEnabled] | ||
public partial class SceneUIComponentInstantiationGroup { } | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.