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,47 @@
using Cysharp.Threading.Tasks;
using Unity.Mathematics;
using UnityEngine.UIElements;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class HousePanelNeedUIView : UIView<HousePanelNeedModel>
{
private VisualElement _valueBarFill;
public override UniTask InitializeAsync(UIService uiService, VisualElement rootElement)
{
base.InitializeAsync(uiService, rootElement);
_valueBarFill = rootElement.Q<VisualElement>(className: "house-panel__need-value-bar-fill");
return UniTask.CompletedTask;
}
protected override void OnNewModel(HousePanelNeedModel model)
{
base.OnNewModel(model);
if (model.RowIndex % 2 == 0) RootElement.Q(className: "house-panel__need").AddToClassList("alt");
UpdateValueBar();
}
protected override void OnModelPropertyChanged(object sender, BindablePropertyChangedEventArgs e)
{
base.OnModelPropertyChanged(sender, e);
switch (e.propertyName)
{
case nameof(HousePanelNeedModel.Value):
UpdateValueBar();
break;
}
}
private void UpdateValueBar()
{
var fillPercent = math.clamp((float)Model.Value / Model.Max, 0, 1) * 100;
_valueBarFill.style.width = Length.Percent(fillPercent);
}
}
}