Interface for Scripts that are part of a Scene. A more complete and less limited API than ScenePublic
public class ScenePrivate : Sansar.Script.InstanceInterfaceRemarks
The ScenePrivate class provides services relating to the Scene.
Members at a glance
Fields
GravityMaximum
public static readonly float GravityMaximumThe maximum gravity magnitude in m/s^2, which is equal to 49.05 or 5 G’s.
Remarks
A value greater than this will clamp to this value.
GravityMinimum
public static readonly float GravityMinimumThe minimum allowed gravity magnitude in m/s^2, which is equal to zero.
Remarks
A value less than this will clamp to this value.
MaximumCastRayResults
public static readonly int MaximumCastRayResultsThe maximum number of results returned from a CastRay, CastSphere or CastBox call. Anything over this will be truncated.
MinimumCastRadius
public static readonly float MinimumCastRadiusThe minimum radius for a CastSphere call or minimum half extents for CastBox. Any value smaller than this will use CastRay instead.
Properties
AgentCount
public uint AgentCount { get; }The number of agents in the Scene.
Value: uint — Unsigned integer count of the number of agents in the Scene.
Remarks
This number changes when agents join and part.
Chat
DefaultGravity
public float DefaultGravity { get; }The default gravity magnitude in the scene in m/s^2, which is equal to 9.81 or 1 G.
Value: float — The default scene gravity magnitude.
Remarks
The direction of the gravity vector is constant.
Example
float sansarGravity = ScenePrivate.DefaultGravity; // Get default gravity in m/s^2HttpClient
public HttpClient HttpClient { get; }Gets the HttpClient for this Scene
Value: HttpClient — The HttpClient Api
Reactions
public Reactions Reactions { get; }Gets the Reactions interface for this Scene
Value: Reactions — The Chat Api
SceneInfo
public SceneInfo SceneInfo { get; }Gets the SceneInfo for this Scene
Value: SceneInfo — The full SceneInfo Api
User
Methods
AddToSceneLibrary
public void AddToSceneLibrary(
ClusterResource resource,
string displayName
)Add an item to the scene library for all users.
| Parameter | Type | Description |
|---|---|---|
resource | ClusterResource | The cluster resource to add. |
displayName | string | The display name shown in the backpack. |
public void AddToSceneLibrary(
ClusterResource resource,
string displayName,
string thumbnailAssetId
)Add an item to the scene library for all users.
| Parameter | Type | Description |
|---|---|---|
resource | ClusterResource | The cluster resource to add. |
displayName | string | The display name shown in the backpack. |
thumbnailAssetId | string | Optional thumbnail asset id shown as the item icon. |
AddToSceneLibraryForAgent
public void AddToSceneLibraryForAgent(
AgentPrivate agent,
ClusterResource resource,
string displayName
)Add an item to the scene library for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
resource | ClusterResource | The cluster resource to add. |
displayName | string | The display name shown in the backpack. |
public void AddToSceneLibraryForAgent(
AgentPrivate agent,
ClusterResource resource,
string displayName,
string thumbnailAssetId
)Add an item to the scene library for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
resource | ClusterResource | The cluster resource to add. |
displayName | string | The display name shown in the backpack. |
thumbnailAssetId | string | Optional thumbnail asset id shown as the item icon. |
CastBox
public RayCastHit[] CastBox(
Sansar.Vector halfExtents,
Sansar.Vector start,
Sansar.Vector end
)Casts a box from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
Returns: RayCastHit[]
Remarks
If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.
public RayCastHit[] CastBox(
Sansar.Vector halfExtents,
Sansar.Quaternion orientation,
Sansar.Vector start,
Sansar.Vector end
)Casts a box from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
Returns: RayCastHit[]
Remarks
If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.
public RayCastHit[] CastBox(
Sansar.Vector halfExtents,
Sansar.Vector start,
Sansar.Vector end,
int maxHits
)Casts a box from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
Remarks
If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.
public RayCastHit[] CastBox(
Sansar.Vector halfExtents,
Sansar.Quaternion orientation,
Sansar.Vector start,
Sansar.Vector end,
int maxHits
)Casts a box from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
Remarks
If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.
CastCapsule
public RayCastHit[] CastCapsule(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Vector start,
Sansar.Vector end
)Casts a capsule from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
Returns: RayCastHit[]
Remarks
If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.
public RayCastHit[] CastCapsule(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Quaternion orientation,
Sansar.Vector start,
Sansar.Vector end
)Casts a capsule from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
Returns: RayCastHit[]
Remarks
If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.
public RayCastHit[] CastCapsule(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Vector start,
Sansar.Vector end,
int maxHits
)Casts a capsule from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
Remarks
If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.
public RayCastHit[] CastCapsule(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Quaternion orientation,
Sansar.Vector start,
Sansar.Vector end,
int maxHits
)Casts a capsule from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
Remarks
If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.
CastRay
public RayCastHit[] CastRay(Sansar.Vector start, Sansar.Vector end)Casts a ray from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.
Remarks
maxHits defaults to 1 if unspecified and will return only the nearest hit.
public RayCastHit[] CastRay(
Sansar.Vector start,
Sansar.Vector end,
int maxHits
)Casts a ray from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.
Remarks
maxHits defaults to 1 if unspecified and will return only the nearest hit.
CastSphere
public RayCastHit[] CastSphere(
float radius,
Sansar.Vector start,
Sansar.Vector end
)Casts a sphere from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
radius | float | The radius of the sphere. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.
Remarks
If the radius is less than ScenePrivate.MinimumCastRadius the call will be forwarded to ScenePrivate.CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.
public RayCastHit[] CastSphere(
float radius,
Sansar.Vector start,
Sansar.Vector end,
int maxHits
)Casts a sphere from start to end and returns an array of collisions along the path.
| Parameter | Type | Description |
|---|---|---|
radius | float | The radius of the sphere. |
start | Sansar.Vector | The initial point of the query. |
end | Sansar.Vector | The end point of the query. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.
Remarks
If the radius is less than ScenePrivate.MinimumCastRadius the call will be forwarded to ScenePrivate.CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.
ClearAllowFlightOverrideForAgent
public void ClearAllowFlightOverrideForAgent(AgentPrivate agent)Clears the per-agent flight override for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
Remarks
The agent will inherit this instance’s default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.
public void ClearAllowFlightOverrideForAgent(
AgentPrivate agent,
Action<Sansar.Script.OperationCompleteEvent> handler
)Clears the per-agent flight override for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
The agent will inherit this instance’s default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.
ClearAllowFlightOverrides
public void ClearAllowFlightOverrides()Clears all per-agent flight overrides in this scene.
Remarks
All agents will inherit this instance’s unchanged default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
public void ClearAllowFlightOverrides(
Action<Sansar.Script.OperationCompleteEvent> handler
)Clears all per-agent flight overrides in this scene.
| Parameter | Type | Description |
|---|---|---|
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
All agents will inherit this instance’s unchanged default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
ClearColorLut
public void ClearColorLut()Removes the scene-wide color LUT override, going back to the LUT chosen in the scene settings.
Remarks
Per-agent overrides persist until cleared or the agent leaves. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
public void ClearColorLut(
Action<Sansar.Script.OperationCompleteEvent> handler
)Removes the scene-wide color LUT override, going back to the LUT chosen in the scene settings.
| Parameter | Type | Description |
|---|---|---|
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Per-agent overrides persist until cleared or the agent leaves. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
ClearColorLutOverrideForAgent
public void ClearColorLutOverrideForAgent(AgentPrivate agent)Clears the per-agent color LUT override for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
Remarks
The agent goes back to the scene-wide LUT. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.
public void ClearColorLutOverrideForAgent(
AgentPrivate agent,
Action<Sansar.Script.OperationCompleteEvent> handler
)Clears the per-agent color LUT override for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
The agent goes back to the scene-wide LUT. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.
ClearColorLutOverrides
public void ClearColorLutOverrides()Clears all per-agent color LUT overrides in this scene.
Remarks
All agents go back to the scene-wide LUT, which is left as it is. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
public void ClearColorLutOverrides(
Action<Sansar.Script.OperationCompleteEvent> handler
)Clears all per-agent color LUT overrides in this scene.
| Parameter | Type | Description |
|---|---|---|
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
All agents go back to the scene-wide LUT, which is left as it is. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
ClearSceneLibrary
public void ClearSceneLibrary()Remove all items from the scene library for all users.
ClearSceneLibraryForAgent
public void ClearSceneLibraryForAgent(AgentPrivate agent)Remove all per-agent scene library items for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
CreateCluster
public ulong CreateCluster(
ClusterResource asset,
Sansar.Vector position,
Sansar.Quaternion rotation,
Sansar.Vector initialVelocity
)Creates a new cluster and adds it to the Scene.
| Parameter | Type | Description |
|---|---|---|
asset | ClusterResource | Asset identifier to create. |
position | Sansar.Vector | Mono.Simd.Vector4f for the initial position. |
rotation | Sansar.Quaternion | Mono.Simd.Vector4f for the initial rotation. |
initialVelocity | Sansar.Vector | Mono.Simd.Vector4f for the initial velocity. |
Returns: ulong — The internal event id for the completion event.
Remarks
The new object may start simulating before the event is triggered.
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong CreateCluster(
ClusterResource asset,
Sansar.Vector position,
Sansar.Quaternion rotation,
Sansar.Vector initialVelocity,
ScenePrivate.CreateClusterHandler handler
)Creates a new cluster and adds it to the Scene.
| Parameter | Type | Description |
|---|---|---|
asset | ClusterResource | Asset identifier to create. |
position | Sansar.Vector | Mono.Simd.Vector4f for the initial position. |
rotation | Sansar.Quaternion | Mono.Simd.Vector4f for the initial rotation. |
initialVelocity | Sansar.Vector | Mono.Simd.Vector4f for the initial velocity. |
handler | ScenePrivate.CreateClusterHandler | Handler to be called when the event completes. |
Returns: ulong — The internal event id for the completion event.
Remarks
The new object may start simulating before the event is triggered.
public void CreateCluster(
ClusterResource asset,
Sansar.Vector position,
Sansar.Quaternion rotation,
Sansar.Vector initialVelocity,
Action<ScenePrivate.CreateClusterData> handler
)Creates a new cluster and adds it to the Scene.
| Parameter | Type | Description |
|---|---|---|
asset | ClusterResource | Asset identifier to create. |
position | Sansar.Vector | Mono.Simd.Vector4f for the initial position. |
rotation | Sansar.Quaternion | Mono.Simd.Vector4f for the initial rotation. |
initialVelocity | Sansar.Vector | Mono.Simd.Vector4f for the initial velocity. |
handler | Action<ScenePrivate.CreateClusterData> | Handler to be called when the event completes. |
Remarks
The new object may start simulating before the event is triggered.
CreateDataStore
public DataStore CreateDataStore(Guid id)Returns a new instance of the DataStore class.
| Parameter | Type | Description |
|---|---|---|
id | Guid | The id of the DataStore to create. |
Returns: DataStore — A new DataStore object.
Remarks
All DataStore objects with a given DataStore.Id share the same database.
public DataStore CreateDataStore(string id)Returns a new instance of the DataStore class.
| Parameter | Type | Description |
|---|---|---|
id | string | String used to generate an id. If the id is a valid Guid then it will be used directly. |
Returns: DataStore — A new DataStore object.
Remarks
All DataStore objects with a given DataStore.Id share the same database. Ensure that this value is kept secret and unique.
FindAgent
public AgentPrivate FindAgent(Sansar.Script.ObjectId objectId)Looks up an Agent associated with the given object id.
| Parameter | Type | Description |
|---|---|---|
objectId | Sansar.Script.ObjectId | The object to find. |
Returns: AgentPrivate — The agent, or null if an agent cannot be found with that id.
Remarks
Agents may leave at any time.
public AgentPrivate FindAgent(Sansar.Script.SessionId sessionId)Looks up an Agent associated with the given session id if they are in the scene.
| Parameter | Type | Description |
|---|---|---|
sessionId | Sansar.Script.SessionId | The session id of the agent to find. |
Returns: AgentPrivate — The agent, or null if an agent cannot be found with that id in the scene.
Remarks
Agents may leave at any time. Attempting to use an Agent or AgentInfo interface for an agent no longer in the scene will throw a NullReferenceException.
public AgentPrivate FindAgent(Guid personaId)Looks up an Agent associated with the given persona id, if they are in the scene.
| Parameter | Type | Description |
|---|---|---|
personaId | Guid | The object to find. |
Returns: AgentPrivate — The agent, or null if an agent cannot be found with that id in the scene.
Remarks
Agents may leave at any time. Attempting to use an Agent or AgentInfo interface for an agent no longer in the scene will throw a NullReferenceException.
FindObject
public ObjectPrivate FindObject(Sansar.Script.ObjectId objectId)Looks up a Object associated with the given object id.
| Parameter | Type | Description |
|---|---|---|
objectId | Sansar.Script.ObjectId | The object to find. |
Returns: ObjectPrivate — The ObjectPrivate, or null if a Object cannot be found with that id.
FindReflective
[Sansar.Script.NonReflective]
public IEnumerable<TInterface> FindReflective<TInterface>(
string name
) where TInterface : classLooks up Reflective objects in the scene that match the interface type by class name.
| Parameter | Type | Description |
|---|---|---|
name | string | The type name of the object’s class to find. |
Type parameters: TInterface: The interface type to find.
Returns: IEnumerable<TInterface> — An IEnumerable which contains all objects of the given type name that match the given interface.
Remarks
The name given corresponds to the Type.FullName of the object. Multiple scripts may define unrelated types of the same name, but only registered objects that match the interface of TInterface will be returned.
FindScript
public object FindScript(Sansar.Script.ScriptId scriptId)Looks up the script object associated with the given scriptId
| Parameter | Type | Description |
|---|---|---|
scriptId | Sansar.Script.ScriptId | The scriptId of the object to find. |
Returns: object — The script object, or null if an script cannot be found with that id in the scene.
Remarks
Objects and their associated scripts may be removed the scene at any time.
GetAgent
public AgentPrivate GetAgent(uint index)Get an AgentPrivate for a specific agent in the Scene.
| Parameter | Type | Description |
|---|---|---|
index | uint | The index of the agent to get. |
Returns: AgentPrivate — Returns null if the index is larger than the number of agents in the Scene, or if the agent is not fully loaded.
Remarks
Agents may appear at different indices as they join and part.
GetAgents
public IEnumerable<AgentPrivate> GetAgents()Returns the current list of Agents in the Scene.
Returns: IEnumerable<AgentPrivate> — The current list of agents in the Scene
GetAllowFlight
public bool GetAllowFlight()Gets the flight availability default for this scene instance.
Returns: bool — The instance default, before per-agent overrides.
Remarks
Flight settings are per instance: they are not saved to the world or shared with clone regions.
GetBoxClosestPoints
public RayCastHit[] GetBoxClosestPoints(
Sansar.Vector halfExtents,
Sansar.Vector origin,
float maximumDistance
)Extends a box with the given half extents the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
origin | Sansar.Vector | The center of the query. |
maximumDistance | float | the maximum distance from the origin to check. |
Returns: RayCastHit[]
public RayCastHit[] GetBoxClosestPoints(
Sansar.Vector halfExtents,
Sansar.Vector origin,
Sansar.Quaternion orientation,
float maximumDistance
)Extends a box with the given half extents the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
origin | Sansar.Vector | The center of the query. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
maximumDistance | float | the maximum distance from the origin to check. |
Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.
public RayCastHit[] GetBoxClosestPoints(
Sansar.Vector halfExtents,
Sansar.Vector origin,
float maximumDistance,
int maxHits
)Extends a box with the given half extents the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
origin | Sansar.Vector | The center of the query. |
maximumDistance | float | the maximum distance from the origin to check. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
public RayCastHit[] GetBoxClosestPoints(
Sansar.Vector halfExtents,
Sansar.Vector origin,
Sansar.Quaternion orientation,
float maximumDistance,
int maxHits
)Extends a box with the given half extents the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
halfExtents | Sansar.Vector | The x,y,z distance from the center of the box to the corresponding face. |
origin | Sansar.Vector | The center of the query. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
maximumDistance | float | the maximum distance from the origin to check. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.
GetCapsuleClosestPoints
public RayCastHit[] GetCapsuleClosestPoints(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Vector origin,
float maximumDistance
)Extends a capsule with the given parameters the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
origin | Sansar.Vector | The base of the capsule. |
maximumDistance | float | the maximum distance from the origin to check. |
Returns: RayCastHit[]
public RayCastHit[] GetCapsuleClosestPoints(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Vector origin,
Sansar.Quaternion orientation,
float maximumDistance
)Extends a capsule with the given parameters the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
origin | Sansar.Vector | The base of the capsule. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
maximumDistance | float | the maximum distance from the origin to check. |
Returns: RayCastHit[]
public RayCastHit[] GetCapsuleClosestPoints(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Vector origin,
float maximumDistance,
int maxHits
)Extends a capsule with the given parameters the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
origin | Sansar.Vector | The base of the capsule. |
maximumDistance | float | the maximum distance from the origin to check. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
public RayCastHit[] GetCapsuleClosestPoints(
Sansar.Vector capsuleStart,
Sansar.Vector capsuleEnd,
float capsuleRadius,
Sansar.Vector origin,
Sansar.Quaternion orientation,
float maximumDistance,
int maxHits
)Extends a capsule with the given parameters the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
capsuleStart | Sansar.Vector | The base point of the capsule. |
capsuleEnd | Sansar.Vector | The end point of the capsule. |
capsuleRadius | float | The radius of the capsule to query. |
origin | Sansar.Vector | The base of the capsule. |
orientation | Sansar.Quaternion | The orientation of the query shape. |
maximumDistance | float | the maximum distance from the origin to check. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
GetGravity
public float GetGravity()Gets the scene’s current acceleration of gravity in m/s^2.
Returns: float — Number indicating the magnitude of gravity in the scene.
Remarks
The default gravity for the scene is ScenePrivate.DefaultGravity
Example
float currentGravity = ScenePrivate.GetGravity(); // Get the current scene gravity in m/s^2GetPortalCreatorName
public string GetPortalCreatorName(Sansar.Script.ObjectId objectId)The name of the user who created the specified portal.
| Parameter | Type | Description |
|---|---|---|
objectId | Sansar.Script.ObjectId |
Returns: string — String
Remarks
User who created the portal.
GetPortalDescription
public string GetPortalDescription(Sansar.Script.ObjectId objectId)Description for the specified portal.
| Parameter | Type | Description |
|---|---|---|
objectId | Sansar.Script.ObjectId |
Returns: string — String
Remarks
The description of the portal.
GetPortalUri
public string GetPortalUri(Sansar.Script.ObjectId objectId)URI destination for the specified portal.
| Parameter | Type | Description |
|---|---|---|
objectId | Sansar.Script.ObjectId |
Returns: string — String
Remarks
The URI of the destination of the portal.
GetSphereClosestPoints
public RayCastHit[] GetSphereClosestPoints(
float radius,
Sansar.Vector origin,
float maximumDistance
)Extends a sphere with the given radius the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
radius | float | The radius of the sphere to query. |
origin | Sansar.Vector | The center of the query. |
maximumDistance | float | the maximum distance from the origin to check. |
Returns: RayCastHit[]
public RayCastHit[] GetSphereClosestPoints(
float radius,
Sansar.Vector origin,
float maximumDistance,
int maxHits
)Extends a sphere with the given radius the maximum distance and returns any hits.
| Parameter | Type | Description |
|---|---|---|
radius | float | The radius of the sphere to query. |
origin | Sansar.Vector | The center of the query. |
maximumDistance | float | the maximum distance from the origin to check. |
maxHits | int | Limit the number of results returned. |
Returns: RayCastHit[]
GetTimeOfDay
public float GetTimeOfDay()Gets the scene’s current time of day in hours.
Returns: float — The time of day in hours, from 0 up to 24.
Remarks
The scene clock runs from 0 at midnight up to 24, so 13.5 is half past one in the afternoon. With the mode TimeOfDayMode.Off this is the time set in the scene settings, which has no effect on the scene until the mode is TimeOfDayMode.Fixed or TimeOfDayMode.Cycle.
Example
float hours = ScenePrivate.GetTimeOfDay(); // Get the scene clock in hoursGetTimeOfDayMode
public TimeOfDayMode GetTimeOfDayMode()Gets how the scene’s time of day runs.
Returns: TimeOfDayMode — The current TimeOfDayMode.
Remarks
See TimeOfDayExample.cs in the Examples folder for more details.
Example
bool dayNight = ScenePrivate.GetTimeOfDayMode() != TimeOfDayMode.Off; // Is the time of day in effect?OverrideAudioStream
public void OverrideAudioStream(string url)Overrides source of web audio streams.
| Parameter | Type | Description |
|---|---|---|
url | string | URL to use. |
Remarks
Applies to all agents in this scene. NOTE: this may cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.
public void OverrideAudioStream(
string url,
Action<Sansar.Script.OperationCompleteEvent> handler
)Overrides source of web audio streams.
| Parameter | Type | Description |
|---|---|---|
url | string | URL to use. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Applies to all agents in this scene. NOTE: this may cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.
OverrideIndexedMediaSource
public void OverrideIndexedMediaSource(
string url,
int mediaIndex,
int mediaWidth,
int mediaHeight,
Action<Sansar.Script.OperationCompleteEvent> handler
)Overrides source of indexed media surfaces.
| Parameter | Type | Description |
|---|---|---|
url | string | URL to use. |
mediaIndex | int | (cMediaChannel only) source index. |
mediaWidth | int | (cMediaChannel only) source width. |
mediaHeight | int | (cMediaChannel only) source height. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Applies to all agents in this scene. NOTE: this will cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.
OverrideMediaSource
public void OverrideMediaSource(string url)Sets stream channel source.
| Parameter | Type | Description |
|---|---|---|
url | string | URL to use. |
public void OverrideMediaSource(
string url,
int mediaWidth,
int mediaHeight
)Overrides source of media surfaces.
| Parameter | Type | Description |
|---|---|---|
url | string | URL to use. |
mediaWidth | int | (cMediaChannel only) source width. |
mediaHeight | int | (cMediaChannel only) source height. |
Remarks
Applies to all agents in this scene. NOTE: this will cause a few seconds of silence while restarting starting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.
public void OverrideMediaSource(
string url,
int mediaWidth,
int mediaHeight,
Action<Sansar.Script.OperationCompleteEvent> handler
)Overrides source of media surfaces.
| Parameter | Type | Description |
|---|---|---|
url | string | URL to use. |
mediaWidth | int | (cMediaChannel only) source width. |
mediaHeight | int | (cMediaChannel only) source height. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Applies to all agents in this scene. NOTE: this will cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.
PerformIndexedMediaAction
public void PerformIndexedMediaAction(
MediaAction action,
int mediaIndex,
Action<Sansar.Script.OperationCompleteEvent> handler
)Performs a specific action on the current media surface index.
| Parameter | Type | Description |
|---|---|---|
action | MediaAction | The action to perform. |
mediaIndex | int | (cMediaChannel only) source index. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Applies to all agents currently in the scene.
PerformMediaAction
public void PerformMediaAction(MediaAction action)Performs a specific action on the current media surface.
| Parameter | Type | Description |
|---|---|---|
action | MediaAction | The action to perform. |
Remarks
Applies to this agent only.
public void PerformMediaAction(
MediaAction action,
Action<Sansar.Script.OperationCompleteEvent> handler
)Performs a specific action on the current media surface.
| Parameter | Type | Description |
|---|---|---|
action | MediaAction | The action to perform. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Applies to all agents currently in the scene.
PlaySound
public PlayHandle PlaySound(
SoundResource soundResource,
PlaySettings playSettings
)Play sound to direct output.
| Parameter | Type | Description |
|---|---|---|
soundResource | SoundResource | The sound resource to play. |
playSettings | PlaySettings | The play parameters. |
Returns: PlayHandle — The play handle for controlling playback.
Remarks
Plays for all agents in this scene.
PlaySoundAtPosition
public PlayHandle PlaySoundAtPosition(
SoundResource soundResource,
Sansar.Vector position,
PlaySettings playSettings
)Play sound at specified position.
| Parameter | Type | Description |
|---|---|---|
soundResource | SoundResource | The sound resource to play. |
position | Sansar.Vector | The absolute position. |
playSettings | PlaySettings | The play parameters. |
Returns: PlayHandle — The play handle for controlling playback.
Remarks
Plays for all agents in this scene. By setting an absolute position, the location of this sound will be static. If you want the sound to move, you must play the sound on an audio component and move the audio component.
PlayStream
public PlayHandle PlayStream(
StreamChannel streamChannel,
float loudness
)Play web audio stream to direct output.
| Parameter | Type | Description |
|---|---|---|
streamChannel | StreamChannel | Channel of the audio stream to play. |
loudness | float | Relative loudness in dB. |
Returns: PlayHandle — The play handle for controlling playback.
Remarks
Plays for all agents in this scene.
PlayStreamAtPosition
public PlayHandle PlayStreamAtPosition(
StreamChannel streamChannel,
Sansar.Vector position,
float loudness
)Play web audio stream at specified position.
| Parameter | Type | Description |
|---|---|---|
streamChannel | StreamChannel | Channel of the audio stream to play. |
position | Sansar.Vector | The absolute position. |
loudness | float | Relative loudness in dB. |
Returns: PlayHandle — The play handle for controlling playback.
Remarks
Plays for all agents in this scene. By setting an absolute position, the location of this sound will be static. If you want the sound to move, you must play the sound on an audio component and move the audio component.
RemoveFromSceneLibrary
public void RemoveFromSceneLibrary(ClusterResource resource)Remove an item from the scene library for all users.
| Parameter | Type | Description |
|---|---|---|
resource | ClusterResource | The cluster resource to remove. |
RemoveFromSceneLibraryForAgent
public void RemoveFromSceneLibraryForAgent(
AgentPrivate agent,
ClusterResource resource
)Remove an item from the scene library for a specific agent.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | The target agent. |
resource | ClusterResource | The cluster resource to remove. |
ResetScene
[Sansar.Script.Interface(Restricted=true)]
public void ResetScene()Restarts the Scene.
Remarks
All clients will be momentarily disconnected.
SetAllowFlight
public void SetAllowFlight(bool allowFlight)Sets the flight availability default for this scene instance.
| Parameter | Type | Description |
|---|---|---|
allowFlight | bool | The default for agents without an explicit override. |
Remarks
Existing overrides persist until cleared or the agent leaves. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
public void SetAllowFlight(
bool allowFlight,
Action<Sansar.Script.OperationCompleteEvent> handler
)Sets the flight availability default for this scene instance.
| Parameter | Type | Description |
|---|---|---|
allowFlight | bool | The default for agents without an explicit override. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Existing overrides persist until cleared or the agent leaves. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
SetColorLut
public void SetColorLut(TextureResource lut)Overrides the scene’s color LUT for everyone in this scene instance.
| Parameter | Type | Description |
|---|---|---|
lut | TextureResource | The LUT texture to grade with, or null to go back to the LUT chosen in the scene settings. |
Remarks
Every user without a per-agent override, see AgentPrivate.SetColorLut, is graded with this LUT in place of the scene settings LUT, including users who join later. A PostFX volume with its own LUT still takes over while a user’s camera is inside it. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
public void SetColorLut(
TextureResource lut,
Action<Sansar.Script.OperationCompleteEvent> handler
)Overrides the scene’s color LUT for everyone in this scene instance.
| Parameter | Type | Description |
|---|---|---|
lut | TextureResource | The LUT texture to grade with, or null to go back to the LUT chosen in the scene settings. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Every user without a per-agent override, see AgentPrivate.SetColorLut, is graded with this LUT in place of the scene settings LUT, including users who join later. A PostFX volume with its own LUT still takes over while a user’s camera is inside it. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.
SetGravity
public void SetGravity(float scale)Sets the scene’s current gravity acceleration in m/s^2.
| Parameter | Type | Description |
|---|---|---|
scale | float | The gravity magnitude. |
Remarks
Set to ScenePrivate.DefaultGravity to return to the default. The valid range is from ScenePrivate.GravityMinimum to ScenePrivate.GravityMaximum. The direction cannot be changed.
Example
ScenePrivate.SetGravity(1.622f); // Set the scene to moon gravity[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong SetGravity(
float scale,
Sansar.Script.ScriptBase.OperationComplete handler
)Sets the scene’s current gravity acceleration in m/s^2.
| Parameter | Type | Description |
|---|---|---|
scale | float | The gravity magnitude. |
handler | Sansar.Script.ScriptBase.OperationComplete | Handler to be called when the event completes. |
Returns: ulong — The return value is an internal event id which can be passed to ScriptBase.WaitFor from a coroutine for synchronous behavior.
Remarks
Set to ScenePrivate.DefaultGravity to return to the default. The valid range is from ScenePrivate.GravityMinimum to ScenePrivate.GravityMaximum. The direction cannot be changed.
Example
ScenePrivate.SetGravity(1.622f); // Set the scene to moon gravitypublic void SetGravity(
float scale,
Action<Sansar.Script.OperationCompleteEvent> handler
)Sets the scene’s current gravity acceleration in m/s^2.
| Parameter | Type | Description |
|---|---|---|
scale | float | The gravity magnitude. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Set to ScenePrivate.DefaultGravity to return to the default. The valid range is from ScenePrivate.GravityMinimum to ScenePrivate.GravityMaximum. The direction cannot be changed.
Example
ScenePrivate.SetGravity(1.622f); // Set the scene to moon gravitySetMegaphone
public void SetMegaphone(AgentPrivate agent, bool enable)Sets the megaphone status of the user.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | Agent to broadcast. |
enable | bool | If true, user’s voice will be heard by everyone in the scene. If false, user’s voice will be spatialized normally. |
public void SetMegaphone(
AgentPrivate agent,
bool enable,
Action<Sansar.Script.OperationCompleteEvent> handler
)Sets the megaphone status of the user.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | Agent to broadcast. |
enable | bool | If true, user’s voice will be heard by everyone in the scene. If false, user’s voice will be spatialized normally. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
SetTimeOfDay
public void SetTimeOfDay(float hours)Sets the scene’s current time of day in hours.
| Parameter | Type | Description |
|---|---|---|
hours | float | The time of day in hours, from 0 at midnight up to 24. 18.5 is half past six in the evening. |
Remarks
Every user in the scene sees the change. With the mode TimeOfDayMode.Cycle the clock carries on running from the new time. The mode is left as it is: the time only takes effect while the mode is TimeOfDayMode.Fixed or TimeOfDayMode.Cycle, see ScenePrivate.SetTimeOfDayMode.
Example
ScenePrivate.SetTimeOfDay(18.5f); // Half past six in the eveningpublic void SetTimeOfDay(
float hours,
Action<Sansar.Script.OperationCompleteEvent> handler
)Sets the scene’s current time of day in hours.
| Parameter | Type | Description |
|---|---|---|
hours | float | The time of day in hours, from 0 at midnight up to 24. 18.5 is half past six in the evening. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Every user in the scene sees the change. With the mode TimeOfDayMode.Cycle the clock carries on running from the new time. The mode is left as it is: the time only takes effect while the mode is TimeOfDayMode.Fixed or TimeOfDayMode.Cycle, see ScenePrivate.SetTimeOfDayMode.
Example
ScenePrivate.SetTimeOfDay(18.5f); // Half past six in the eveningSetTimeOfDayMode
public void SetTimeOfDayMode(TimeOfDayMode mode)Sets how the scene’s time of day runs.
| Parameter | Type | Description |
|---|---|---|
mode | TimeOfDayMode | The new mode. |
Remarks
Every user in the scene sees the change. The clock carries on from its current reading: switching from TimeOfDayMode.Cycle to TimeOfDayMode.Fixed holds the sun where it is, and switching back sets it moving again from there. A scene built with the mode TimeOfDayMode.Off has its sun baked into the lighting, so the bounced sunlight stays as built when a script turns the time of day on; build the scene with the mode TimeOfDayMode.Fixed or TimeOfDayMode.Cycle for the full effect.
Example
ScenePrivate.SetTimeOfDayMode(TimeOfDayMode.Cycle); // Start the day and night cyclepublic void SetTimeOfDayMode(
TimeOfDayMode mode,
Action<Sansar.Script.OperationCompleteEvent> handler
)Sets how the scene’s time of day runs.
| Parameter | Type | Description |
|---|---|---|
mode | TimeOfDayMode | The new mode. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
Every user in the scene sees the change. The clock carries on from its current reading: switching from TimeOfDayMode.Cycle to TimeOfDayMode.Fixed holds the sun where it is, and switching back sets it moving again from there. A scene built with the mode TimeOfDayMode.Off has its sun baked into the lighting, so the bounced sunlight stays as built when a script turns the time of day on; build the scene with the mode TimeOfDayMode.Fixed or TimeOfDayMode.Cycle for the full effect.
Example
ScenePrivate.SetTimeOfDayMode(TimeOfDayMode.Cycle); // Start the day and night cycleShakeCameraAtPosition
public CameraShakeHandle ShakeCameraAtPosition(
Sansar.Vector position,
float radius,
CameraShakeSettings settings
)Requests a shake for current players, attenuated by camera distance from a world position.
| Parameter | Type | Description |
|---|---|---|
position | Sansar.Vector | Stationary world-space source position in meters; W is ignored. |
radius | float | World-space radius in meters, clamped to 0 through 1000; 0 is inert. |
settings | CameraShakeSettings | Settings to snapshot, or null for fresh default settings. |
Returns: CameraShakeHandle — A non-null handle for this script’s request, including inert requests.
Remarks
Strength falls to zero at the radius using each player’s unshaken viewing camera. Only players present at the call receive it. Direction remains in camera space. Player comfort settings and VR limits can reduce or suppress any shake. Leaving the world ends that player’s shake. Only the rendered view changes; camera transforms, audio and targeting are unaffected.
/* This example is licensed under the Creative Commons Attribution 4.0 International License. * Copyright 2026 Sansar, Inc. https://creativecommons.org/licenses/by/4.0/ */
using System;using System.Collections.Generic;using Sansar;using Sansar.Script;using Sansar.Simulation;
/// <summary>Demonstrates camera shake with chat commands on the default channel.</summary>/// <remarks>Use /shake rumble, jitter, sway, impact, near, engine or stop./// Engine toggles a continuous rumble for the sender; stop clears this script's shakes for everyone./// An optional CameraComponent on this object fixes the view for current and future users./// Player comfort settings and VR limits can reduce or suppress the motion.</remarks>public class CameraShakeExample : SceneObjectScript{ private CameraComponent camera; private readonly Dictionary<SessionId, CameraShakeHandle> engines = new Dictionary<SessionId, CameraShakeHandle>();
/// <summary>Sets up chat commands and the optional fixed camera.</summary> public override void Init() { ObjectPrivate.TryGetFirstComponent(out camera); ScenePrivate.User.Subscribe(User.AddUser, OnUserAdded); ScenePrivate.User.Subscribe(User.RemoveUser, OnUserRemoved); ScenePrivate.Chat.Subscribe(Chat.DefaultChannel, OnChat, true);
// Script reloads also need to set up users who are already in the world. foreach (AgentPrivate agent in ScenePrivate.GetAgents()) { SetCamera(agent); }
// The Debug local-source live test requires this marker from the real body. Log.Write("CameraShakeExample ready (real shake body): /shake rumble, jitter, sway, impact, near, engine, stop"); }
private void SetCamera(AgentPrivate agent) { if (camera != null && agent != null && agent.IsValid) { agent.Client.SetActiveCamera(camera, ScriptCameraControlMode.AgentControlOnly); } }
private void OnUserAdded(UserData data) { SetCamera(ScenePrivate.FindAgent(data.User)); }
private void OnUserRemoved(UserData data) { // Leaving the world ends that player's shake; discard the old session's handle. engines.Remove(data.User); }
private bool StopEngine(SessionId sessionId) { CameraShakeHandle engine; if (!engines.TryGetValue(sessionId, out engine)) { return false; }
engine.Stop(0.25f); engines.Remove(sessionId); return true; }
private void OnChat(ChatData data) { string[] words = data.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length != 2 || !words[0].Equals("/shake", StringComparison.OrdinalIgnoreCase)) { return; }
// SourceId identifies the sender, rather than the object running this script. AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId); if (agent == null || !agent.IsValid) { return; } SessionId sessionId = agent.AgentInfo.SessionId;
switch (words[1].ToLowerInvariant()) { case "rumble": // Presets are mutable: edit before starting. Starts snapshot the settings. CameraShakeSettings rumble = CameraShakeSettings.Earthquake(); rumble.Direction = new Vector(1, 0.5f, 0); agent.Client.ShakeCamera(rumble); break;
case "jitter": agent.Client.ShakeCamera(new CameraShakeSettings { Pattern = CameraShakePattern.Jitter, Magnitude = 0.25f, Duration = 1.0f // Frequency 0 uses Jitter's default of 20 Hz. }); break;
case "sway": // Long side-to-side motion for the fixed-camera pixel-displacement test. agent.Client.ShakeCamera(new CameraShakeSettings { Pattern = CameraShakePattern.Sway, Magnitude = 0.6f, Frequency = 2.0f, Duration = 6.0f, Direction = new Vector(1, 0, 0), FadeOut = 0.3f }); break;
case "impact": // Landing: one downward kick. Duration 0 would still give just one kick. agent.Client.ShakeCamera(CameraShakeSettings.Impact(new Vector(0, -1, 0))); break;
case "near": // Only players present now receive this explosion. Their camera distance // from this object's world position controls falloff to zero at 20 meters. ScenePrivate.ShakeCameraAtPosition(ObjectPrivate.Position, 20.0f, CameraShakeSettings.Explosion()); break;
case "engine": // Send again to stop; separate sessions retain separate handles. if (!StopEngine(sessionId)) { engines[sessionId] = agent.Client.ShakeCamera(CameraShakeSettings.EngineRumble()); } break;
case "stop": StopEngine(sessionId); // Both stop-all scopes affect only shakes requested by this script. agent.Client.StopAllCameraShakes(); ScenePrivate.StopAllCameraShakes(); engines.Clear(); break; } }}Source: Examples/CameraShakeExample.cs in the Sansar 47.10.0 client ScriptApi snapshot.
StopAllCameraShakes
public void StopAllCameraShakes(float fadeOut)Stops all shakes from the calling script on current players in this scene.
| Parameter | Type | Description |
|---|---|---|
fadeOut | float | Ending fade in seconds, clamped to 0 through 5; defaults to 0.1. |
Remarks
0 stops immediately. Shakes from other scripts are unaffected.
ToString
public override string ToString()A string representation of this object.
Returns: string — A string representation of this object.
Remarks
The format of this string may change between releases.
VoiceBroadcastStart
[System.Obsolete("Deprecated. use ScenePrivate.SetMegaphone(agent, true) instead", false)]
public void VoiceBroadcastStart(AgentPrivate agent)Start broadcasting agent’s voice to the voice broadcast channel.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | Agent to broadcast. |
Remarks
Plays for all agents in this scene.
VoiceBroadcastStop
[System.Obsolete("Deprecated. use ScenePrivate.SetMegaphone(agent, false) instead", false)]
public void VoiceBroadcastStop(AgentPrivate agent)Stop broadcasting agent’s voice to voice broadcast channel.
| Parameter | Type | Description |
|---|---|---|
agent | AgentPrivate | Agent to stop broadcasting. |
Remarks
Stops for all agents in this scene.
VoiceBroadcastStopAll
[System.Obsolete("Deprecated. use AgentPrivate.SetMegaphone(false) instead", false)]
public void VoiceBroadcastStopAll()Stop broadcasting all voices to voice broadcast channel.
Remarks
Stops for all agents in this scene.
Used in examples
- FollowThePath.cs
- MoverExample1.cs
- MoverExample3.cs
- ReflectiveDetectorExample.cs
- StatsExample.cs
- TeleportHotkeys.cs
- VisitorTrackerExample.cs
- AgentGravityExample.cs
- AgentScaleExample.cs
- BanHammerExample.cs
- BroadcastUsers.cs
CameraShakeExample.cs
…and 56 more examples in the snapshot.
Generated from the Sansar 47.10.0 client ScriptApi snapshot.