Info
- Shared values and lists as ScriptableObject assets. Scripts reference the asset, not each other
- Module
Polis.Core.ScriptableArchitecture
- E.g. the rig hands are
TransformScriptableVariables, so avatars and tools find them without a direct reference
- Create assets with Assets / Create Scriptable Object or the Create Scriptable Object toolbar button (there are no
CreateAssetMenu entries)
Usage
AScriptableVariable<T> - one shared value
Value - get / set, implicit cast to T
DefaultValue - start value on play
IsReadOnly - blocks writes
event Action ValueChanged - only when the value really changes
- Ready variable types
BoolScriptableVariable, IntScriptableVariable, FloatScriptableVariable, DoubleScriptableVariable
StringScriptableVariable, Vector3ScriptableVariable
GameObjectScriptableVariable, TransformScriptableVariable
AScriptableList<T> - shared IList<T>
- Events
ItemsChanged, ItemsAdded, ItemsRemoved
- Ready:
GameObjectScriptableList, TransformScriptableList
ScriptableVariableField<T> - inspector switch between a Local value and a Scriptable variable, implicit cast to T
Assigners
- Register scene objects into the assets (
AScriptableAssigner)
ObjectVariableAssigner / TransformVariableAssigner - set a variable
GameObjectScriptableListAssigner / TransformScriptableListAssigner - add self to a list, remove on disable
- Optional
ICondition - assign while true, unassign when false
Helpers
ToggleByScriptableVariable - drives an AToggleState from a bool variable
ScriptableTransformFollow - follows a transform variable
ScriptableVariableAssignAction - IAction that sets a variable
Example
[SerializeField]
private BoolScriptableVariable _Muted;
private void OnEnable() => _Muted.ValueChanged += Refresh;
private void OnDisable() => _Muted.ValueChanged -= Refresh;
private void Refresh() => _icon.SetActive(_Muted.Value);
Extending