Files
riversong-code-showcase/Source/Riversong/Game/UI/Framework/UIModel.cs
2026-05-21 16:04:49 +02:00

33 lines
880 B
C#

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine.UIElements;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class UIModel : IUIModel
{
public event EventHandler<BindablePropertyChangedEventArgs> propertyChanged;
public event Action Changed;
protected void SetProperty<T>(ref T field, T value, [CallerMemberName] string property = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return;
field = value;
NotifyPropertyChanged(property);
}
protected void NotifyPropertyChanged(string property = null)
{
propertyChanged?.Invoke(this, new BindablePropertyChangedEventArgs(property));
}
public void NotifyChanged()
{
Changed?.Invoke();
}
}
}