1- using Gameframe . ScriptableObjects . Events ;
1+ using System ;
2+ using System . ComponentModel ;
3+ using System . Runtime . CompilerServices ;
4+ using Gameframe . ScriptableObjects . Events ;
5+ using JetBrains . Annotations ;
26using UnityEngine ;
37
48namespace Gameframe . ScriptableObjects . Variables
59{
6- public class BaseVariable : ScriptableObject
10+ public class BaseVariable : ScriptableObject , INotifyPropertyChanged
711 {
812 [ SerializeField ]
913 protected GameEvent onValueChanged ;
@@ -19,6 +23,44 @@ public GameEvent OnValueChanged
1923 return onValueChanged ;
2024 }
2125 }
26+
27+ /// <summary>
28+ /// INotifyPropertyChanged interface implemented to support Gameframe.Bindings
29+ /// </summary>
30+ #region INotifyPropertyChanged
31+
32+ public event PropertyChangedEventHandler PropertyChanged ;
33+
34+ [ NotifyPropertyChangedInvocator ]
35+ protected void OnPropertyChanged ( [ CallerMemberName ] string propertyName = null )
36+ {
37+ try
38+ {
39+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
40+ }
41+ catch ( Exception e )
42+ {
43+ Debug . LogException ( e , this ) ;
44+ }
45+ if ( onValueChanged != null )
46+ {
47+ onValueChanged . Raise ( ) ;
48+ }
49+ }
50+
51+ #endregion
52+
53+ protected bool SetProperty < T > ( ref T field , T value , [ CallerMemberName ] string propertyName = null )
54+ {
55+ if ( ! Equals ( field , value ) )
56+ {
57+ field = value ;
58+ OnPropertyChanged ( propertyName ) ;
59+ return true ;
60+ }
61+ return false ;
62+ }
63+
2264 }
2365}
2466
0 commit comments