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.
Sansar Namespace
Some base types including Vector and Quaternion.
Sansar.Script Namespace
Basic scripting internals.
Sansar.Script.Testing Namespace
Tools for testing scripts.
Sansar.Simulation Namespace
Events and related types.
Sansar.Utility Namespace
Miscellaneous Utility types.
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.
- Scene Object Script for scripts attached to objects that are part of the scene.
- 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.
- Sansar.Simulation.AgentScript for scripts that are attached directly to agents.
- Sansar currently supports:
- Create a new class that extends the chosen base class.
C# Example public class MyScript : SceneObjectScript
- 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 TrackAgentHits = true; public bool TrackObjectHits = true;
- Override init() to subscribe to events or initialize coroutines that will wait for events.
C# Example public override void Init() { // Subscribe to Add User events. Use SessionId.Invalid to track all users. ScenePrivate.User.Subscribe(UserEvents.AddUser, SessionId.Invalid, AddUser); }
- Write event handlers and coroutines as needed to process events.
C# Example void AddUser(string Action, Sansar.Script.SessionId User, string Data) { // Lookup the name of the agent. string name = ScenePrivate.FindAgent(User).AgentInfo.Name; ScenePrivate.Chat.MessageAllUsers(string.Format("Welcome {0}!", name)); }
- 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.
Copyright ©2017
0 Comments