cz.xprees.variables 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,10 +9,13 @@ namespace Xprees.Variables.Base
9
9
  private void OnEnable()
10
10
  {
11
11
  hideFlags = HideFlags.DontUnloadUnusedAsset;
12
- ResetState();
12
+ ForceResetState();
13
13
  }
14
14
 
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();
16
19
  }
17
20
 
18
21
  /// <summary>
@@ -22,9 +25,18 @@ namespace Xprees.Variables.Base
22
25
  /// <typeparam name="T">Unity Serializable</typeparam>
23
26
  public class VariableBaseSO<T> : VariableBaseSO
24
27
  {
28
+ [Tooltip("Value to which the variable will be reset on OnEnable or ResetState call.")]
25
29
  [SerializeField] protected T defaultValue;
30
+
31
+ [Tooltip("Current value of variable - Runtime only value.")]
26
32
  [SerializeField] private T currentValue;
27
33
 
34
+ [Header("Settings")]
35
+ [Tooltip("If true, the variable will not be reset when calling ResetState()."
36
+ + " However, it will still be reset on OnEnable and when ForceResetState() is called. "
37
+ + "Useful for game-system variables where runtime value should persist unless explicitly reset.")]
38
+ [SerializeField] protected bool protectedDontReset = false;
39
+
28
40
  public virtual T CurrentValue
29
41
  {
30
42
  get => currentValue;
@@ -35,6 +47,7 @@ namespace Xprees.Variables.Base
35
47
  }
36
48
  }
37
49
 
50
+ /// Event invoked when CurrentValue changes.
38
51
  public UnityAction<T> onValueChanged;
39
52
 
40
53
  public void SetValue(T value) => CurrentValue = value;
@@ -44,6 +57,14 @@ namespace Xprees.Variables.Base
44
57
  public static implicit operator T(VariableBaseSO<T> variable) =>
45
58
  variable != null ? variable.CurrentValue : default;
46
59
 
47
- public override void ResetState() => CurrentValue = defaultValue;
60
+ public override void ResetState()
61
+ {
62
+ if (protectedDontReset) return; // skip reset if protected
63
+
64
+ ForceResetState();
65
+ }
66
+
67
+ public override void ForceResetState() => CurrentValue = defaultValue;
68
+
48
69
  }
49
70
  }
@@ -24,7 +24,12 @@ namespace Xprees.Variables.Base
24
24
  get => ModifyValue(variable.CurrentValue);
25
25
  set
26
26
  {
27
- if (disableWrite.Value) return;
27
+ if (disableWrite.Value)
28
+ {
29
+ Debug.LogWarning($"Trying to set value of {name} but writing is disabled.", this);
30
+ return;
31
+ }
32
+
28
33
  variable.CurrentValue = ModifyValue(value);
29
34
  }
30
35
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cz.xprees.variables",
3
3
  "displayName": "Variables",
4
- "version": "1.0.13",
4
+ "version": "1.0.15",
5
5
  "unity": "2021.3",
6
6
  "description": "This package contains a system for creating variables based on ScriptableObjects in Editor.",
7
7
  "license": "Apache-2.0",