Command events are generated by the client when input events occur.
public class CommandData : Sansar.Script.EventDataRemarks
| Command | Default Key Binding |
|---|---|
| Trigger | Left Mouse Button |
| PrimaryAction | F |
| SecondaryAction | R |
| Modifier | Shift |
| Action1 to Action0 | Number keys 1 to 0 |
| Confirm | Enter |
| Cancel | Escape |
| SelectLeft | Left arrow |
| SelectRight | Right arrow |
| SelectUp | Up arrow |
| SelectDown | Down arrow |
| Keypad0 to Keypad9 | Numberpad keys 0 to 9 |
| KeypadEnter | Numberpad Enter |
While the agent is seated, the movement controls also generate keypad commands for vehicle driving: W/A/S/D and the VR or gamepad left analog stick map to Keypad8 (forward), Keypad4 (left), Keypad6 (right), and Keypad2 plus Keypad5 (back/brake). These aliases are only delivered while seated; when standing, the movement controls move the avatar without generating commands. Stick axes generate digital press/release events at half deflection, not continuous analog values. Sources holding the same keypad command are combined: the first source sends Pressed and the last source to release sends Released, retaining the first source’s ControlPoint.
An example script for handling client commands:
Example
/* This content is licensed under the terms of the Creative Commons Attribution 4.0 International License. * When using this content, you must: * • Acknowledge that the content is from the Sansar Knowledge Base. * • Include our copyright notice: "2022 Sansar, Inc." * • Indicate that the content is licensed under the Creative Commons Attribution-Share Alike 4.0 International License. * • Include the URL for, or link to, the license summary at https://creativecommons.org/licenses/by-sa/4.0/deed.hi (and, if possible, to the complete license terms at https://creativecommons.org/licenses/by-sa/4.0/legalcode. * For example: * "This work uses content from the Sansar Knowledge Base. © 2022 Sansar, Inc." Licensed under the Creative Commons Attribution 4.0 International License (license summary available at https://creativecommons.org/licenses/by/4.0/ and complete license terms available at https://creativecommons.org/licenses/by/4.0/legalcode)." */
using Sansar.Script;using Sansar.Simulation;
public class CommandExample : SceneObjectScript{ #region ScriptParameters [Tooltip(@"The command to enable listening for the Action Command. Default: Confirm (Enter)")] [DefaultValue("Confirm")] [DisplayName("Subscribe Command")] public readonly string SubscribeCommand;
[Tooltip(@"The command to disable listening for the Action Command. Default: Cancel (Escape)")] [DefaultValue("Cancel")] [DisplayName("Unsubscribe Command")] public readonly string UnsubscribeCommand;
[Tooltip(@"If the command has been subscribed to by the 'Subscribe Command', this will log the action to the script console.")] [DefaultValue("Trigger")] [DisplayName("Action Command")] public readonly string ActionCommand; #endregion ScriptParameters
public override void Init() { // Subscribe to new user events; ScenePrivate.User.Subscribe(User.AddUser, NewUser); }
IEventSubscription subscription = null;
void NewUser(UserData newUser) { Client client = ScenePrivate.FindAgent(newUser.User).Client;
// CommandReceived will be called every time the command it triggered on the client // CommandCanceled will be called if the subscription fails if (SubscribeCommand != "") { client.SubscribeToCommand(SubscribeCommand, CommandAction.Pressed, (data) => { if (subscription == null) { Log.Write(GetType().Name, $"[{SubscribeCommand}] Subscribing to {ActionCommand}."); subscription = client.SubscribeToCommand(ActionCommand, CommandAction.All, CommandReceived, CommandCanceled); } }, CommandCanceled); }
if (UnsubscribeCommand != "") { client.SubscribeToCommand(UnsubscribeCommand, CommandAction.Pressed, (data) => { if (subscription != null) { Log.Write(GetType().Name, $"[{UnsubscribeCommand}] Unsubscribing to {ActionCommand}."); subscription.Unsubscribe(); subscription = null; } }, CommandCanceled); } }
void CommandReceived(CommandData command) { Log.Write(GetType().Name, $"Received command {command.Command}: {command.Action}. Targeting Info: {command.TargetingComponent}, Origin:{command.TargetingOrigin}, Position:{command.TargetingPosition}, Normal{command.TargetingNormal}"); }
void CommandCanceled(CancelData data) { Log.Write(GetType().Name, "Subscription canceled: "+data.Message); }
}Source: Examples/CommandExample.cs in the Sansar 47.10.0 client ScriptApi snapshot.
Members at a glance
| Kind | Members |
|---|---|
| Properties | Action · CameraControlMode · Command · ControlPoint · IsAimTarget · MouseLookMode · SessionId · SimulationFrame · TargetingComponent · TargetingNormal · TargetingOrigin · TargetingPosition |
| Methods | ToString |
Properties
Action
public CommandAction Action { get; }The action which occurred.
CameraControlMode
public CameraControlMode CameraControlMode { get; }Command
public string Command { get; }The command which occurred.
ControlPoint
public ControlPointType ControlPoint { get; }IsAimTarget
public bool IsAimTarget { get; }MouseLookMode
public bool MouseLookMode { get; }SessionId
public Sansar.Script.SessionId SessionId { get; }The client which generated the event.
SimulationFrame
public ulong SimulationFrame { get; }TargetingComponent
public Sansar.Script.ComponentId TargetingComponent { get; }TargetingNormal
public Sansar.Vector TargetingNormal { get; }TargetingOrigin
public Sansar.Vector TargetingOrigin { get; }TargetingPosition
public Sansar.Vector TargetingPosition { get; }Methods
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.
Used in examples
- TeleportHotkeys.cs
- BanHammerExample.cs
- CommandExample.cs
- PewPewExample.cs
- ScriptLibrary/Scene/Hotkey.cs
- ScriptLibrary/Scene/Screenshot.cs
- ScriptLibrary/Scene/Selector.cs
- ScriptLibrary/Scene/Target.cs
- ScriptLibrary/Scene/Targeting.cs
Generated from the Sansar 47.10.0 client ScriptApi snapshot.