Extend the Interaction System
The Interaction System provides many Actions to add interaction to your VIROO Application. On some occasions you may encounter cases that aren't solved by it and you will have to create your own code to solve.
You can create your own Action to extend the VIROO Interaction System. This is the best way to add functionality to your VIROO Application that has to run on all users across the network.
An Action contains a block of logic that you can call on the local user instance, or on those of all users who have joined the session.
Create your own Action
Start by creating a script for your own Action, for example, CustomAction.cs
. This class has to inherit from BroadcastObjectAction
.
If you are using AssemblyDefinition files in your project BroadcastObjectAction class is found in the
Viroo.Interactions
assembly.
In your new class you will have to implement the LocalExecuteImplementation
function, this will be the code block that your Action will use.
using Viroo.Interactions;
public class CustomAction : BroadcastObjectAction
{
protected override void LocalExecuteImplementation(string data)
{
// Your code goes here
}
}
Then, when you want to invoke your Action, you will have two functions you can call on this object:
- Execute: your Action is run for all users. The
LocalExecuteImplementation
method will be called for all users. - LocalExecute: your Action is only run by the local player. The code you have inside
LocalExecuteImplementation
will only be run by the user who calls the function.
Add this script to your VIROO Application
Now, you can add this script to any GameObject in any of the scenes of your VIROO Application.
Now, you can use it in any other of your components to call the Execute or LocalExecute functions.
Calling your Action from an Interaction
Drag the Action to one of the callbacks that the interaction has exposed, such as Activate
. The Action will be triggered when the event is dragged into is executed.
In the following example, the Custom Action code is called after interacting with an object with RayInteraction.
Calling your Action from another Action
If you want your Action to be called after another Action has been executed, you can use the Actions events to do so.
In the following example, the Action will be called when another object finishes moving, using the OnActionFinished
event.
Note
Notice that the method being called is LocalExecute and not Execute. The reason for this is that, when the MoveAction is called, that Actions is already being called for all users in the session.
When chaining Actions, you need to use LocalExecute on nested Actions, and only the first one should be called with Execute.