riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine.UIElements;
using IServiceProvider = DanieleMarotta.RiversongCodeShowcase.IServiceProvider;
namespace DanieleMarotta.RiversongCodeShowcase
{
[GameSystemGroup(typeof(UISystemGroup))]
public class UIInitializationSystem : GameSystem, IServiceProvider, IInitializable, IDisposable
{
[InjectService]
private GameConfig _config;
[InjectService]
private ISoundPlayer _soundPlayer;
private IUIRoot _uiRoot;
private UIService _uiService;
private TextFormatHelper _textFormatHelper;
public UIInitializationSystem(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
public void RegisterServices(IServiceLocator serviceLocator)
{
serviceLocator.RegisterService(new UIState());
_uiService = new UIService();
serviceLocator.RegisterService(_uiService);
_textFormatHelper = new TextFormatHelper();
serviceLocator.RegisterService(_textFormatHelper);
}
public async UniTask InitializeAsync()
{
var uiRootGameObject = await _config.UI.RootPrefab.InstantiateAsync();
_uiRoot = uiRootGameObject.GetComponent<IUIRoot>();
await _uiRoot.Initialize(_uiService);
_uiRoot.ElementClicked += OnElementClicked;
_uiService.UIRoot = _uiRoot;
_uiService.TemplateLibrary = await _config.UI.TemplateLibrary.LoadAssetAsync<UITemplateLibrary>();
_uiService.TextFormatHelper = _textFormatHelper;
}
public void Dispose()
{
_uiRoot.ElementClicked -= OnElementClicked;
_uiRoot.Dispose();
}
private void OnElementClicked(ClickEvent e)
{
if (e.target is not VisualElement element) return;
if (element.GetFirstAncestorOrSelf(static candidate => candidate is Button || candidate.ClassListContains("ui-click")) == null) return;
_soundPlayer.Play(SystemSoundId.UIClick);
}
}
}