Info
IActivation - something that fires an "activate" event: a click, a trigger, an input action. Code in Polis.Core.Utils.Activations, XR ones in Polis.Core.XRTools.Activations
- Pick it in the inspector instead of writing a script for every button or trigger
Usage
Register(Action) / Unregister(Action)
RegisterDisposable(Action) extension - registers and returns an IDisposable that unregisters
- Implementations
ButtonActivation - UI Button.onClick
ColliderActivation - a ColliderEvents component, event type TriggerEnter, TriggerExit, ColliderEnter, ColliderExit
InputActionActivation - InputActionReference performed. Enables the action and its map
XRInteractableActivation - select and activate of an XR interactable, each filtered by an interaction layer mask (Nothing disables that event). XRInteractableSelectActivation and XRInteractableActivateActivation are obsolete, use this one
CompoundActivation - a list of activations, any of them fires
- Examples in code:
ToggleOnActivate, BugReportButton, TeleportButton, FormController, ViewSwitch pages
Example
[SerializeReference]
private IActivation _Activation;
private void OnEnable() => _Activation?.Register(OnActivated);
private void OnDisable() => _Activation?.Unregister(OnActivated);
Extending
- Inherit
AWrapperActivation, implement StartListening / StopListening, call InvokeListeners(). It starts listening with the first listener and stops after the last one is removed
Gotchas