cz.xprees.variables 1.0.3
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.
- package/.github/workflows/deploy.yml +30 -0
- package/Editor/ReferenceDrawerBase.cs +58 -0
- package/Editor/ReferenceDrawerBase.cs.meta +3 -0
- package/Editor/cz.xprees.variables.editor.asmdef +18 -0
- package/Editor/cz.xprees.variables.editor.asmdef.meta +3 -0
- package/Editor.meta +3 -0
- package/Runtime/Aggregations/BoolAggregation.cs +28 -0
- package/Runtime/Aggregations/BoolAggregation.cs.meta +3 -0
- package/Runtime/Aggregations.meta +3 -0
- package/Runtime/Base/ReferenceBase.cs +63 -0
- package/Runtime/Base/ReferenceBase.cs.meta +3 -0
- package/Runtime/Base/VariableAgregationBaseSO.cs +25 -0
- package/Runtime/Base/VariableAgregationBaseSO.cs.meta +3 -0
- package/Runtime/Base/VariableBaseSO.cs +49 -0
- package/Runtime/Base/VariableBaseSO.cs.meta +11 -0
- package/Runtime/Base/VariableModifierBaseSO.cs +33 -0
- package/Runtime/Base/VariableModifierBaseSO.cs.meta +11 -0
- package/Runtime/Base.meta +3 -0
- package/Runtime/Modifiers/BoolModifier.cs +24 -0
- package/Runtime/Modifiers/BoolModifier.cs.meta +3 -0
- package/Runtime/Modifiers.meta +3 -0
- package/Runtime/Primitive/BoolVariable.cs +10 -0
- package/Runtime/Primitive/BoolVariable.cs.meta +3 -0
- package/Runtime/Primitive/FloatVariable.cs +10 -0
- package/Runtime/Primitive/FloatVariable.cs.meta +3 -0
- package/Runtime/Primitive/IntVariable.cs +10 -0
- package/Runtime/Primitive/IntVariable.cs.meta +3 -0
- package/Runtime/Primitive/StringVariable.cs +10 -0
- package/Runtime/Primitive/StringVariable.cs.meta +3 -0
- package/Runtime/Primitive.meta +3 -0
- package/Runtime/Reference/Primitive/BoolReference.cs +13 -0
- package/Runtime/Reference/Primitive/BoolReference.cs.meta +3 -0
- package/Runtime/Reference/Primitive/FloatReference.cs +13 -0
- package/Runtime/Reference/Primitive/FloatReference.cs.meta +3 -0
- package/Runtime/Reference/Primitive/IntReference.cs +17 -0
- package/Runtime/Reference/Primitive/IntReference.cs.meta +3 -0
- package/Runtime/Reference/Primitive/StringReference.cs +17 -0
- package/Runtime/Reference/Primitive/StringReference.cs.meta +3 -0
- package/Runtime/Reference/Primitive.meta +3 -0
- package/Runtime/Reference.meta +3 -0
- package/Runtime/cz.xprees.variables.asmdef +16 -0
- package/Runtime/cz.xprees.variables.asmdef.meta +3 -0
- package/Runtime.meta +3 -0
- package/package.json +28 -0
- package/package.json.meta +3 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish to NPM registry
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
- release/*
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish-gpr:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
packages: write
|
|
15
|
+
environment: Production
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-node@v4
|
|
19
|
+
with:
|
|
20
|
+
node-version: 20
|
|
21
|
+
- name: Version Patcher
|
|
22
|
+
uses: justalemon/VersionPatcher@v0.8
|
|
23
|
+
with:
|
|
24
|
+
version: 1.0.${{ github.run_number }}
|
|
25
|
+
npm-files: 'package.json'
|
|
26
|
+
- run: npm i
|
|
27
|
+
- uses: JS-DevTools/npm-publish@v3
|
|
28
|
+
with:
|
|
29
|
+
token: ${{ secrets.NPM_AUTH_TOKEN }}
|
|
30
|
+
access: public
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// ------------------------------------------------------------------------------------------------------
|
|
2
|
+
// Heavily inspired by Ryan Hipple, 10/04/17 from Unite 2017 - Game Architecture with Scriptable Objects
|
|
3
|
+
// ------------------------------------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
using UnityEditor;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
using Xprees.Variables.Base;
|
|
8
|
+
|
|
9
|
+
namespace Xprees.Variables.Editor.Editor
|
|
10
|
+
{
|
|
11
|
+
[CustomPropertyDrawer(typeof(ReferenceBase<>), true)]
|
|
12
|
+
public class ReferenceDrawerBase : PropertyDrawer
|
|
13
|
+
{
|
|
14
|
+
/// Options to display in the popup to select constant or variable.
|
|
15
|
+
private readonly string[] _popupOptions = { "Inlined Value", "Variable" };
|
|
16
|
+
|
|
17
|
+
private GUIStyle _popupStyle;
|
|
18
|
+
|
|
19
|
+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
20
|
+
{
|
|
21
|
+
_popupStyle ??= new GUIStyle(GUI.skin.GetStyle("PaneOptions"))
|
|
22
|
+
{
|
|
23
|
+
imagePosition = ImagePosition.ImageOnly,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
label = EditorGUI.BeginProperty(position, label, property);
|
|
27
|
+
position = EditorGUI.PrefixLabel(position, label);
|
|
28
|
+
|
|
29
|
+
EditorGUI.BeginChangeCheck();
|
|
30
|
+
// Get properties
|
|
31
|
+
var useConstant = property.FindPropertyRelative("useInlined");
|
|
32
|
+
var constantValue = property.FindPropertyRelative("inlinedValue");
|
|
33
|
+
var variable = property.FindPropertyRelative("variable");
|
|
34
|
+
|
|
35
|
+
// Calculate rect for configuration button
|
|
36
|
+
var buttonRect = new Rect(position);
|
|
37
|
+
buttonRect.yMin += _popupStyle.margin.top;
|
|
38
|
+
buttonRect.width = _popupStyle.fixedWidth + _popupStyle.margin.right;
|
|
39
|
+
position.xMin = buttonRect.xMax;
|
|
40
|
+
|
|
41
|
+
// Store old indent level and set it to 0, the PrefixLabel takes care of it
|
|
42
|
+
var indent = EditorGUI.indentLevel;
|
|
43
|
+
EditorGUI.indentLevel = 0;
|
|
44
|
+
|
|
45
|
+
var result = EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, _popupOptions, _popupStyle);
|
|
46
|
+
|
|
47
|
+
useConstant.boolValue = result == 0;
|
|
48
|
+
|
|
49
|
+
EditorGUI.PropertyField(position, useConstant.boolValue ? constantValue : variable, GUIContent.none);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if (EditorGUI.EndChangeCheck()) property.serializedObject.ApplyModifiedProperties();
|
|
53
|
+
|
|
54
|
+
EditorGUI.indentLevel = indent;
|
|
55
|
+
EditorGUI.EndProperty();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cz.xprees.variables.editor",
|
|
3
|
+
"rootNamespace": "Xprees.Variables.Editor",
|
|
4
|
+
"references": [
|
|
5
|
+
"cz.xprees.variables"
|
|
6
|
+
],
|
|
7
|
+
"includePlatforms": [
|
|
8
|
+
"Editor"
|
|
9
|
+
],
|
|
10
|
+
"excludePlatforms": [],
|
|
11
|
+
"allowUnsafeCode": false,
|
|
12
|
+
"overrideReferences": false,
|
|
13
|
+
"precompiledReferences": [],
|
|
14
|
+
"autoReferenced": true,
|
|
15
|
+
"defineConstraints": [],
|
|
16
|
+
"versionDefines": [],
|
|
17
|
+
"noEngineReferences": false
|
|
18
|
+
}
|
package/Editor.meta
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Linq;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
using Xprees.Variables.Base;
|
|
5
|
+
|
|
6
|
+
namespace Xprees.Variables.Aggregations
|
|
7
|
+
{
|
|
8
|
+
[CreateAssetMenu(menuName = "Variables/Aggregations/Bool", fileName = "BoolVarAgg")]
|
|
9
|
+
public class BoolAggregation : VariableAggregationBaseSO<bool>
|
|
10
|
+
{
|
|
11
|
+
[SerializeField] protected BoolAggregator aggregator = BoolAggregator.And;
|
|
12
|
+
|
|
13
|
+
protected override bool AggregateValue(VariableBaseSO<bool>[] variableBases) => aggregator switch
|
|
14
|
+
{
|
|
15
|
+
BoolAggregator.And => variables.All(v => v.CurrentValue),
|
|
16
|
+
BoolAggregator.Or => variables.Any(v => v.CurrentValue),
|
|
17
|
+
BoolAggregator.Xor => variables.Aggregate(false, (current, v) => current ^ v.CurrentValue),
|
|
18
|
+
_ => throw new ArgumentOutOfRangeException()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public enum BoolAggregator
|
|
23
|
+
{
|
|
24
|
+
And,
|
|
25
|
+
Or,
|
|
26
|
+
Xor,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// ------------------------------------------------------------------------------------------------------
|
|
2
|
+
// Heavily inspired by Ryan Hipple, 10/04/17 from Unite 2017 - Game Architecture with Scriptable Objects
|
|
3
|
+
// ------------------------------------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
using System;
|
|
6
|
+
using UnityEngine.Events;
|
|
7
|
+
using Xprees.Core;
|
|
8
|
+
|
|
9
|
+
namespace Xprees.Variables.Base
|
|
10
|
+
{
|
|
11
|
+
[Serializable]
|
|
12
|
+
public class ReferenceBase<T> : IResettable
|
|
13
|
+
{
|
|
14
|
+
private T _defaultInlinedValue; // Used to reset state of inlined value
|
|
15
|
+
|
|
16
|
+
public bool useInlined = true;
|
|
17
|
+
public T inlinedValue;
|
|
18
|
+
public VariableBaseSO<T> variable;
|
|
19
|
+
|
|
20
|
+
public UnityAction<T> onValueChanged = delegate { };
|
|
21
|
+
|
|
22
|
+
public ReferenceBase()
|
|
23
|
+
{
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public ReferenceBase(T value)
|
|
27
|
+
{
|
|
28
|
+
useInlined = true;
|
|
29
|
+
inlinedValue = value;
|
|
30
|
+
_defaultInlinedValue = value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public T Value
|
|
34
|
+
{
|
|
35
|
+
get => useInlined ? inlinedValue : variable.CurrentValue;
|
|
36
|
+
set
|
|
37
|
+
{
|
|
38
|
+
if (useInlined)
|
|
39
|
+
{
|
|
40
|
+
inlinedValue = value;
|
|
41
|
+
onValueChanged?.Invoke(value);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
variable.SetValue(value);
|
|
46
|
+
onValueChanged?.Invoke(value); // ignores that variable has its own onValueChanged
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static implicit operator T(ReferenceBase<T> reference) => reference != null ? reference.Value : default;
|
|
51
|
+
|
|
52
|
+
public virtual void ResetState()
|
|
53
|
+
{
|
|
54
|
+
if (useInlined)
|
|
55
|
+
{
|
|
56
|
+
inlinedValue = _defaultInlinedValue;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
variable.ResetState();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
|
|
3
|
+
namespace Xprees.Variables.Base
|
|
4
|
+
{
|
|
5
|
+
public abstract class VariableAggregationBaseSO<T> : VariableBaseSO<T>
|
|
6
|
+
{
|
|
7
|
+
[Header("Aggregation")]
|
|
8
|
+
[Tooltip("Aggregated variables.")]
|
|
9
|
+
[SerializeField] protected VariableBaseSO<T>[] variables;
|
|
10
|
+
|
|
11
|
+
private void OnEnable()
|
|
12
|
+
{
|
|
13
|
+
hideFlags = HideFlags.DontUnloadUnusedAsset;
|
|
14
|
+
ResetState();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public override T CurrentValue
|
|
18
|
+
{
|
|
19
|
+
get => AggregateValue(variables);
|
|
20
|
+
set => Debug.LogWarning($"{GetType().Name} on {name} - cannot set value for aggregation!"); // cannot set value of aggregation
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected abstract T AggregateValue(VariableBaseSO<T>[] variableBases);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
using Xprees.Core;
|
|
4
|
+
|
|
5
|
+
namespace Xprees.Variables.Base
|
|
6
|
+
{
|
|
7
|
+
public abstract class VariableBaseSO : DescriptionBaseSO
|
|
8
|
+
{
|
|
9
|
+
private void OnEnable()
|
|
10
|
+
{
|
|
11
|
+
hideFlags = HideFlags.DontUnloadUnusedAsset;
|
|
12
|
+
ResetState();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public override abstract void ResetState();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Base class for all variables ScriptableObjects.
|
|
20
|
+
/// Object holds the state on runtime, but reset every time OnEnable to defaultValue.
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <typeparam name="T">Unity Serializable</typeparam>
|
|
23
|
+
public class VariableBaseSO<T> : VariableBaseSO
|
|
24
|
+
{
|
|
25
|
+
[SerializeField] protected T defaultValue;
|
|
26
|
+
[SerializeField] private T currentValue;
|
|
27
|
+
|
|
28
|
+
public virtual T CurrentValue
|
|
29
|
+
{
|
|
30
|
+
get => currentValue;
|
|
31
|
+
set
|
|
32
|
+
{
|
|
33
|
+
currentValue = value;
|
|
34
|
+
onValueChanged?.Invoke(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public UnityAction<T> onValueChanged;
|
|
39
|
+
|
|
40
|
+
public void SetValue(T value) => CurrentValue = value;
|
|
41
|
+
|
|
42
|
+
public void SetValue(VariableBaseSO<T> variable) => CurrentValue = variable.CurrentValue;
|
|
43
|
+
|
|
44
|
+
public static implicit operator T(VariableBaseSO<T> variable) =>
|
|
45
|
+
variable != null ? variable.CurrentValue : default;
|
|
46
|
+
|
|
47
|
+
public override void ResetState() => CurrentValue = defaultValue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using Xprees.Variables.Reference.Primitive;
|
|
3
|
+
|
|
4
|
+
namespace Xprees.Variables.Base
|
|
5
|
+
{
|
|
6
|
+
public abstract class VariableModifierBaseSO<T> : VariableBaseSO<T>
|
|
7
|
+
{
|
|
8
|
+
[Header("Modifier")]
|
|
9
|
+
[Tooltip("Variable to modify.")]
|
|
10
|
+
[SerializeField] protected VariableBaseSO<T> variable;
|
|
11
|
+
|
|
12
|
+
[Space]
|
|
13
|
+
[SerializeField] private BoolReference disableWrite = new(true);
|
|
14
|
+
|
|
15
|
+
private void OnEnable()
|
|
16
|
+
{
|
|
17
|
+
hideFlags = HideFlags.DontUnloadUnusedAsset;
|
|
18
|
+
ResetState();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public override T CurrentValue
|
|
22
|
+
{
|
|
23
|
+
get => ModifyValue(variable.CurrentValue);
|
|
24
|
+
set
|
|
25
|
+
{
|
|
26
|
+
if (disableWrite.Value) return;
|
|
27
|
+
variable.CurrentValue = ModifyValue(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected abstract T ModifyValue(T value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using Xprees.Variables.Base;
|
|
3
|
+
|
|
4
|
+
namespace Xprees.Variables.Modifiers
|
|
5
|
+
{
|
|
6
|
+
[CreateAssetMenu(menuName = "Variables/Modifiers/Bool modifier", fileName = "BoolVarMod")]
|
|
7
|
+
public class BoolModifier : VariableModifierBaseSO<bool>
|
|
8
|
+
{
|
|
9
|
+
[SerializeField] protected BoolModifiers variableModifier = BoolModifiers.Identity;
|
|
10
|
+
|
|
11
|
+
protected override bool ModifyValue(bool value) => variableModifier switch
|
|
12
|
+
{
|
|
13
|
+
BoolModifiers.Identity => value,
|
|
14
|
+
BoolModifiers.Not => !value,
|
|
15
|
+
_ => value,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public enum BoolModifiers
|
|
20
|
+
{
|
|
21
|
+
Identity,
|
|
22
|
+
Not,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using Xprees.Variables.Base;
|
|
3
|
+
|
|
4
|
+
namespace Xprees.Variables.Reference.Primitive
|
|
5
|
+
{
|
|
6
|
+
[Serializable]
|
|
7
|
+
public class IntReference : ReferenceBase<int>
|
|
8
|
+
{
|
|
9
|
+
public IntReference()
|
|
10
|
+
{
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public IntReference(int value) : base(value)
|
|
14
|
+
{
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using Xprees.Variables.Base;
|
|
3
|
+
|
|
4
|
+
namespace Xprees.Variables.Reference.Primitive
|
|
5
|
+
{
|
|
6
|
+
[Serializable]
|
|
7
|
+
public class StringReference : ReferenceBase<string>
|
|
8
|
+
{
|
|
9
|
+
public StringReference()
|
|
10
|
+
{
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public StringReference(string value = null) : base(value)
|
|
14
|
+
{
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cz.xprees.variables",
|
|
3
|
+
"rootNamespace": "Xprees.Variables",
|
|
4
|
+
"references": [
|
|
5
|
+
"cz.xprees.core"
|
|
6
|
+
],
|
|
7
|
+
"includePlatforms": [],
|
|
8
|
+
"excludePlatforms": [],
|
|
9
|
+
"allowUnsafeCode": false,
|
|
10
|
+
"overrideReferences": false,
|
|
11
|
+
"precompiledReferences": [],
|
|
12
|
+
"autoReferenced": true,
|
|
13
|
+
"defineConstraints": [],
|
|
14
|
+
"versionDefines": [],
|
|
15
|
+
"noEngineReferences": false
|
|
16
|
+
}
|
package/Runtime.meta
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cz.xprees.variables",
|
|
3
|
+
"displayName": "Variables",
|
|
4
|
+
"version": "1.0.3",
|
|
5
|
+
"unity": "2021.3",
|
|
6
|
+
"description": "This package contains a system for creating variables based on ScriptableObjects in Editor.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"category": "Core",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"cz.xprees.core": "1.0.0"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"Unity",
|
|
14
|
+
"Variables",
|
|
15
|
+
"ScriptableObjects"
|
|
16
|
+
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "xprees",
|
|
19
|
+
"email": "xprees.developer@gmail.com",
|
|
20
|
+
"url": "https://xprees.com"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/xprees/unity-variables/issues"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"url": "https://github.com/xprees/unity-variables"
|
|
27
|
+
}
|
|
28
|
+
}
|