43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using Unity.Properties;
|
|
using UnityEngine;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class HousePanelNeedModel : UIModel
|
|
{
|
|
private int _value;
|
|
|
|
private int _max;
|
|
|
|
public int RowIndex { get; set; }
|
|
|
|
[CreateProperty] public string Name { get; set; }
|
|
|
|
[CreateProperty] public Sprite Icon { get; set; }
|
|
|
|
[CreateProperty] public int Value { get; set; }
|
|
|
|
[CreateProperty] public int Max { get; set; }
|
|
|
|
[CreateProperty] public string ValueString => $"{Mathf.RoundToInt(100 * Mathf.Clamp01(Value / (float)Max))}%";
|
|
|
|
public void Initialize(int rowIndex, string name, Sprite icon, int value, int max)
|
|
{
|
|
RowIndex = rowIndex;
|
|
Name = name;
|
|
Icon = icon;
|
|
Value = value;
|
|
Max = max;
|
|
}
|
|
|
|
public void UpdateValue(int value)
|
|
{
|
|
if (Value == value) return;
|
|
|
|
Value = value;
|
|
|
|
NotifyPropertyChanged(nameof(Value));
|
|
NotifyPropertyChanged(nameof(ValueString));
|
|
}
|
|
}
|
|
} |