riversong code showcase
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user