@@ -9,10 +9,13 @@ public abstract class VariableBaseSO : DescriptionBaseSO
99 private void OnEnable ( )
1010 {
1111 hideFlags = HideFlags . DontUnloadUnusedAsset ;
12- ResetState ( ) ;
12+ ForceResetState ( ) ;
1313 }
1414
15- public override abstract void ResetState ( ) ;
15+ /// Force reset state regardless of any protection settings.
16+ public abstract void ForceResetState ( ) ;
17+
18+ public override void ResetState ( ) => ForceResetState ( ) ;
1619 }
1720
1821 /// <summary>
@@ -22,9 +25,17 @@ private void OnEnable()
2225 /// <typeparam name="T">Unity Serializable</typeparam>
2326 public class VariableBaseSO < T > : VariableBaseSO
2427 {
28+ [ Tooltip ( "Value to which the variable will be reset on OnEnable or ResetState call." ) ]
2529 [ SerializeField ] protected T defaultValue ;
30+
31+ [ Tooltip ( "Current value of variable - Runtime only value." ) ]
2632 [ SerializeField ] private T currentValue ;
2733
34+ [ Header ( "Settings" ) ]
35+ [ Tooltip (
36+ "If true, the variable will not be reset on plain ResetState call. It will be reset only on OnEnable. Useful for game-system variables." ) ]
37+ [ SerializeField ] protected bool protectedDontReset = false ;
38+
2839 public virtual T CurrentValue
2940 {
3041 get => currentValue ;
@@ -35,6 +46,7 @@ public virtual T CurrentValue
3546 }
3647 }
3748
49+ /// Event invoked when CurrentValue changes.
3850 public UnityAction < T > onValueChanged ;
3951
4052 public void SetValue ( T value ) => CurrentValue = value ;
@@ -44,6 +56,14 @@ public virtual T CurrentValue
4456 public static implicit operator T ( VariableBaseSO < T > variable ) =>
4557 variable != null ? variable . CurrentValue : default ;
4658
47- public override void ResetState ( ) => CurrentValue = defaultValue ;
59+ public override void ResetState ( )
60+ {
61+ if ( protectedDontReset ) return ; // skip reset if protected
62+
63+ ForceResetState ( ) ;
64+ }
65+
66+ public override void ForceResetState ( ) => CurrentValue = defaultValue ;
67+
4868 }
4969}
0 commit comments