While the Intent Action is meant to be reusable across scenes, sometimes you need to handle an intent directly in a scene. For this, use the LexiconIntentHandler component.
Drop the intent asset into the slot and add methods to the Process event. These methods might call Unity methods on scene objects (like the example with the directional light above). Or, they might call a method from a script. If you write a method, the signature should look like this:
using UnityEngine;
using Mixspace.Lexicon;
public class ManageLights : MonoBehaviour
{
public Light light;
public void TurnOnLight(LexiconRuntimeResult result)
{
light.enabled = true;
}
public void TurnOffLight(LexiconRuntimeResult result)
{
light.enabled = false;
}
}
Advantages of Intent Handlers:
- Can hold references to objects in your scene
- Possibly code-free
- Multiple handler functions in one code file
Advantages of Intent Actions:
- Instant functionality when adding intent to workspace
- Does not clutter up scene
- Reusable across scenes
- More easily shared