Sansar Script API
Sansar uses C# scripts to provide dynamic behaviors and interactions.
Sansar uses a limited subset of the mono .net api. Click here for a list of C# libraries usable by Sansar scripts.
Documentation for the Sansar script API.
Creating a Sansar script:
Choose a base class for your script depending on where the script will live and what APIs it needs access to. There are three core APIs: Object, Scene, and Agent. Each of these is split into two interfaces: a Public interface that is generally available and a Private interface that is a more complete superset of the Public interface. The base class chosen will determine which APIs are available to the script.
Sansar currently supports:
Scene Object Script for scripts attached to objects that are part of the scene. This will give it access to Sansar.Simulation.ObjectPrivate for the object the script is on, and Sansar.Simulation.ScenePrivate for the scene the object is a part of.
There is planned support for:
Sansar.Simulation.AgentScript for scripts that are attached directly to agents. This will give it access to Sansar.Simulation.ObjectPrivate for the avatar object, Sansar.Simulation.AgentPrivate for the agent the script is on, and Sansar.Simulation.ScenePublic for the scene the agent is currently in.
Sansar.Simulation.SceneScript for scripts that are attached directly to the experience. This will give it access to the Sansar.Simulation.ScenePrivate interface for the scene the script is attached to.
Sansar.Simulation.ObjectScript for scripts attached to objects that are not part of the scene. This will give it access to Sansar.Simulation.ObjectPrivate for the object the script is on, and Sansar.Simulation.ScenePublic for the scene the object is currently in.
Create a new class that extends the chosen base class.
C# Example
Create public fields of supported types for any parameters that should be set in the object properties when editing the scene.
C# Example
public bool TrackObjectHits = true;
Override init() to subscribe to events or initialize coroutines that will wait for events.
C# Example
{
} |
Write event handlers and coroutines as needed to process events.
C# Example
{
} |
Upload the script in Sansar via the "Upload" button in inventory while editing a scene.
Errors and Warnings will show in the upload window.
Some APIs are "Restricted": generally these are unstable APIs that are being tested. Since the APIs may change or even be removed in the future scripts that use them should not be sold or traded.
The allowed C# libraries are intitially severely limited but will be expanded over time.
Once successully compiled the script will show up in inventory. Drag it from there onto an object in the scene.
Only successfully compiled scripts will be added to inventory.
Edit the properties on the object to set any parameters from the public fields set in step 3 above.
Save and publish the scene.
Have more questions? Ask in our Discord!
Last updated