cz.xprees.variables 1.0.13 → 1.0.14

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,17 @@ 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(
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
+
28
39
  public virtual T CurrentValue
29
40
  {
30
41
  get => currentValue;
@@ -35,6 +46,7 @@ namespace Xprees.Variables.Base
35
46
  }
36
47
  }
37
48
 
49
+ /// Event invoked when CurrentValue changes.
38
50
  public UnityAction<T> onValueChanged;
39
51
 
40
52
  public void SetValue(T value) => CurrentValue = value;
@@ -44,6 +56,14 @@ namespace Xprees.Variables.Base
44
56
  public static implicit operator T(VariableBaseSO<T> variable) =>
45
57
  variable != null ? variable.CurrentValue : default;
46
58
 
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
+
48
68
  }
49
69
  }
@@ -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.14",
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",