cz.xprees.variables 1.0.18 → 1.0.19

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.
@@ -17,7 +17,37 @@ namespace Xprees.Variables.Base
17
17
  public T inlinedValue;
18
18
  public VariableBaseSO<T> variable;
19
19
 
20
- public UnityAction<T> onValueChanged = delegate { };
20
+ // Internal event for inlined value changes, since VariableBaseSO already has its own onValueChanged event.
21
+ private UnityAction<T> _onInlinedValueChanged;
22
+
23
+ // ReSharper disable once InconsistentNaming
24
+ /// Event invoked when Value changes.
25
+ public event UnityAction<T> onValueChanged
26
+ {
27
+ add
28
+ {
29
+ var shouldRedirectToVarEvent = !useInlined && variable != null;
30
+ if (shouldRedirectToVarEvent)
31
+ {
32
+ variable.onValueChanged += value;
33
+ return;
34
+ }
35
+
36
+ _onInlinedValueChanged += value;
37
+ }
38
+
39
+ remove
40
+ {
41
+ var shouldRedirectToVarEvent = !useInlined && variable != null;
42
+ if (shouldRedirectToVarEvent)
43
+ {
44
+ variable.onValueChanged -= value;
45
+ return;
46
+ }
47
+
48
+ _onInlinedValueChanged -= value;
49
+ }
50
+ }
21
51
 
22
52
  public ReferenceBase()
23
53
  {
@@ -38,12 +68,12 @@ namespace Xprees.Variables.Base
38
68
  if (useInlined)
39
69
  {
40
70
  inlinedValue = value;
41
- onValueChanged?.Invoke(value);
71
+ _onInlinedValueChanged?.Invoke(value); // Invoke inlined value change event
42
72
  return;
43
73
  }
44
74
 
75
+ // VariableBaseSO will invoke its own onValueChanged event, so no need to invoke here.
45
76
  variable.SetValue(value);
46
- onValueChanged?.Invoke(value); // ignores that variable has its own onValueChanged
47
77
  }
48
78
  }
49
79
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cz.xprees.variables",
3
3
  "displayName": "Variables",
4
- "version": "1.0.18",
4
+ "version": "1.0.19",
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",