11using System ;
2+ using System . ComponentModel ;
3+ using System . Runtime . CompilerServices ;
24using Gameframe . ScriptableObjects . Events ;
5+ using JetBrains . Annotations ;
36using UnityEngine ;
47
58namespace Gameframe . ScriptableObjects . Locks
69{
710 [ CreateAssetMenu ( menuName = MenuNames . LockMenu + "Lock" ) ]
8- public class GameLock : ScriptableObject
11+ public class GameLock : ScriptableObject , INotifyPropertyChanged
912 {
1013 [ NonSerialized ]
1114 private int lockCount = 0 ;
@@ -65,8 +68,22 @@ public void Unlock()
6568 }
6669
6770 private void RaiseValueChanged ( )
71+ {
72+ OnPropertyChanged ( nameof ( Locked ) ) ;
73+ }
74+
75+ /// <summary>
76+ /// INotifyPropertyChanged interface implemented to support Gameframe.Bindings
77+ /// </summary>
78+ #region INotifyPropertyChanged
79+
80+ public event PropertyChangedEventHandler PropertyChanged ;
81+
82+ [ NotifyPropertyChangedInvocator ]
83+ private void OnPropertyChanged ( string propertyName = null )
6884 {
6985 var value = Locked ;
86+
7087 if ( value )
7188 {
7289 if ( lockedEvent != null )
@@ -81,8 +98,27 @@ private void RaiseValueChanged()
8198 unlockedEvent . Raise ( ) ;
8299 }
83100 }
84- OnValueChanged ? . Invoke ( value ) ;
101+
102+ try
103+ {
104+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
105+ }
106+ catch ( Exception e )
107+ {
108+ Debug . LogException ( e , this ) ;
109+ }
110+
111+ try
112+ {
113+ OnValueChanged ? . Invoke ( value ) ;
114+ }
115+ catch ( Exception e )
116+ {
117+ Debug . LogException ( e , this ) ;
118+ }
85119 }
120+
121+ #endregion
86122
87123 }
88124}
0 commit comments