Create Custom Code

Sylvain Joly

Search Knowledge Base by Keyword

You are here:

Create Custom Code

With little knowledge of C# code, you can create and add your own custom code to the SpatialStories toolkit.

You can create Custom Conditions (CC) and Custom Actions (CA). These scripts are modules that plug into the basic conditions and actions of the SpatialStories’ core.

Custom Actions

Custom Actions allow you to trigger any action you want other than Audio or Animation. A custom action is a C# script that you can add as a separate component of the interaction you want. The action will be triggered like a normal action and along with any other specified action as soon as conditions are valid.

The structure of a Custom Action looks like follows:

using Gaze;
using UnityEngine;


[AddComponentMenu(“SpatialStories/Custom Actions/CA_MyCustomAction”)] /*this adds the script in the list of components of the Editor*/

public class CA_MyCustomAction : Gaze_AbstractBehaviour
{
/*initialize your variables here*/

protected override void OnTrigger()
{
/*Whatever action I want to happen when the interaction is triggered.*/
}

}

Custom Conditions

Custom Conditions allow you to consider a specific condition for your interactions other than the ones already provided. A custom condition is a C# script that you can add as a separate component of the interaction you want. In order for the interaction to consider it as a condition you have to check Custom Condition under the conditions script (you will see the name of your CC in the Editor). Custom conditions can be anything from geolocation coordinates to a keyboard key pressed or a word recognized by a speech recognition algorithm.

The structure of a Custom Condition can vary depending on what your condition is but the basic code looks like follows:

using UnityEngine;
using Gaze;

namespace SpatialStories

{

[AddComponentMenu(“SpatialStories/Custom Conditions/CC_LanguageChanged”)]

/*this adds the script in the list of components of the Editor*/

public class CC_MyCustomCondition : Gaze_AbstractConditions
{

/*initialize your variables here*/

/*create any function you need for your condition*/

// Update is called once per frame
void Update()
{
ValidateCustomCondition(true);

/*this validates the condition*/
}

}

}