Table of Contents

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 are not solved by it and you will have to create your own code to solve.

In many cases, the best way to add functionality to your VIROO Application, that has to be executed on all users across the network, is to create your own Action to extend the VIROO Interaction System.

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 execute your Action, you will have two functions you can call on this object:

  • Execute: your action is executed for all users. The LocalExecuteImplementation method will be called for all users.
  • LocalExecute: your action is only executed by the local player. The code you have inside LocalExecuteImplementation will only be executed 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.

custom-action-component.png

Now, you can use it in any other of your components to call the Execute or LocalExecute functions.

Calling your Action as a result of an Interaction

Drag your Action to the Actions list of any Interaction and the Action will be triggered whenever that Interaction is performed.

In the following example, we have the Custom Action code called as a result of interacting with an object with RayInteraction.

custom-action-from-interaction.png

Calling your Action as a result of another Action

If you want your action to be called as a result of another action being executed, you can use the Actions events to do so.

In the following example, the action will be called when another object finishes moving, so we are using the OnActionFinished event.

custom-action-from-action.png

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 usually need to use LocalExecute on nested Actions, and only the first one should be called with Execute.