Simple Script

SimpleScript Class

Extend SimpleScript to create a script that can be used on content that is natively in the scene. This is the primary script type in Sansar.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", true)] public abstract class SimpleScript : Sansar.Script.ScriptBase

Member Details

SimpleScript Constructor

This constructor is called before any properties have been set. Override Sansar.Script.SimpleScript.SimpleInit() to initialize the script after properties have been set and events setup.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected SimpleScript ()

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


GetSubscription Method

Get the IEventSubscription for any of the registered event subscription methods

Syntax

Parameters

methodName

The n

Returns

An IEventSubscription interface that can be used to unsubscribe from a registered event.

Remarks

Example

C# Example

            GetSubscription("OnChat").Unsubscribe();

|

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


Init Method

Init() initializes all event subscriptions for the overridable methods in SimpleScript

Syntax

[Sansar.Script.Api] public override sealed void Init ()

See Also

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


ObjectPrivate Property

The ObjectPrivate this script is attached to if it is attached to an object.

Syntax

[Sansar.Script.NonReflective] [get: Sansar.Script.Interface] public ObjectPrivate ObjectPrivate { protected get; set; }

Value

The scene object this script is attached to if it is attached to an object, null otherwise.

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


OnAddUser Method

Code in OnAddUser will run whenever a user enters the scene.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void OnAddUser (AgentPrivate agent)

See Also

Parameters

agent

The AgentPrivate for the user that has joined the scene.

Remarks

Example

C# Example

            protected override OnAddUser(AgentPrivate agent)
        {
           agent.SendChat($"Welcome to the {ScenePrivate.SceneInfo.ExperienceName} scene!");
        }
        

|

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


OnChat Method

Code in OnChat will run whenever chat is heard.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void OnChat (ChatData data)

See Also

Parameters

data

ChatData for the message.

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


OnCollision Method

Receive events whenever the object this script is on collides with something or someone.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void OnCollision (CollisionData data)

See Also

Parameters

data

The CollisionData about the collision.

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


OnRemoveUser Method

Code in OnRemoveUser will run whenever a user leaves the scene.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void OnRemoveUser (AgentInfo data)

See Also

Parameters

data

UserData for the user that has left the scene.

Remarks

Example

C# Example

// This event occurs when a user leaves the scene
        protected override void OnRemoveUser(AgentInfo info)
        {
            Log.Write($"{info.Name} has left the region.");
        }

|

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


OnScriptEvent Method

Receive events from other scripts.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void OnScriptEvent (Sansar.Script.ScriptId sourceScriptId, object data)

See Also

Parameters

sourceScriptId

The Sansar.Script.ScriptId of the script that sent the message

data

The data sent by another script, as an object.

Remarks

Example

C# Example

            // Send events to this handler from other simple scripts with: PostScriptEvent("AddPosition", myVector);
        [OnScriptEventOptions(EventName="AddPosition")]
        protected override void OnScriptEvent(object eventData)
        {
            Vector newPos = eventData as Vector;
            if (newPos != null) AllPositions.Add(newPos);
        }
        

|

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


OnTimer Method

Code in OnTimer will run at regular intervals.

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void OnTimer ()

Remarks

Example

C# Example

            // Set OnTimer to happen once every minute.
        [OnTimerOptions(Rate=60)]
        protected override void OnTimer()
        

|

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


RigidBodyComponent Property

The first RigidBodyComponent on ObjectPrivate

Syntax

[get: Sansar.Script.Interface] protected RigidBodyComponent RigidBodyComponent { get; }

Value

The first SimpleScript.RigidBodyComponent on the object this script is attached to.

Remarks

This is a convenience for:

C# Example

            RigidBodyComponent rigidbody;
         if (ObjectPrivate != null && ObjectPrivate.TryGetFirstComponent(out rigidbody))
        {
            // Do something with rigidbody
        }
        

|

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


ScenePrivate Property

The Scene API for the Scene this script is a part of if the script is attached to scene content.

Syntax

[Sansar.Script.NonReflective] [get: Sansar.Script.Interface] public ScenePrivate ScenePrivate { protected get; set; }

Value

The Scene API for this scene if this script was attached to scene content, null otherwise.

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0


SimpleInit Method

Override SimpleInit for script setup, such as subscribing to other events or

Syntax

[Sansar.Script.Interface] [System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)] protected virtual void SimpleInit ()

Remarks

Requirements

Namespace: Sansar.Simulation Assembly: Sansar.Simulation (in Sansar.Simulation.dll) Assembly Versions: 1.1.0.0



Last updated