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,41 @@
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine.UIElements;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class UIService
{
public IUIRoot UIRoot { get; set; }
public UITemplateLibrary TemplateLibrary { get; set; }
public TextFormatHelper TextFormatHelper { get; set; }
public async UniTask<UIView> CreateView(Type type, VisualElement rootElement)
{
var view = (UIView)Activator.CreateInstance(type);
await view.InitializeAsync(this, rootElement);
return view;
}
}
public static class UIServiceExtensions
{
public static async UniTask CreateViews<TModel, TView>(this UIService uiService, List<TModel> models, VisualElement container, VisualTreeAsset template)
where TModel : UIModel where TView : UIView<TModel>
{
container.Clear();
foreach (var model in models)
{
var element = template.CloneTree();
container.Add(element);
var view = (TView)await uiService.CreateView(typeof(TView), element);
view.SetModel(model);
}
}
}
}