riversong code showcase
This commit is contained in:
33
Source/Riversong/Game/UI/Framework/UIModel.cs
Normal file
33
Source/Riversong/Game/UI/Framework/UIModel.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user