Breakroom is now Sinewave Campus. Book a meeting

SScript

客户端场景
在此类中TypeName
  1. 函数
  2. TypeName
  3. TrackingAllowed
  4. TrackingRequest
  5. GetResource
  6. LogEvent
  7. Log
  8. 属性
  9. Inventory
  10. Persistence
  11. Scene
  12. Grid
  13. Host
  14. Physics
  15. Math
  16. String
  17. Input
  18. Camera
  19. WebServices
  20. Network
  21. PostFX
  22. AudioAnalyser
  23. Tween
  24. UI
  25. Dialogues
  26. Shared
  27. Quests
  28. Economy
  29. Groups
  30. Activity
  31. RenderSettings
  32. Profile
  33. Photos
  34. Videos
  35. MusicDirectory
  36. Journey
  37. GameTester
  38. RuntimeType
  39. Platform
  40. SessionID
  41. InEditor
  42. Version
  43. FullVersionString
  44. Resources
  45. Time
  46. ServerTime
  47. LocalTime
  48. LoginTime
  49. ServerTimeUnix
  50. LocalTimeUnix
  51. DeltaTime
  52. PreviewServer
  53. ComponentName
成员 51
函数TypeNameReturn the type name of the value.
函数TrackingAllowedReturns true on white-label grids when the user has opted into tracking for the given key.
函数TrackingRequestDisplays a consent prompt (EULA-style) asking the user to allow tracking for a given key.
函数GetResourceReturns a reference to a SResource using it's Resource name.
函数LogEventLogs an analytics event to the server on white-label grids.
函数LogLog a message to console.
属性InventoryAllows access to the users inventory
属性PersistenceStores information between user sessions, and for other users
属性SceneAllows access to the current scene graph (objects and avatars in the scene, and other information)
属性Grid–
属性HostAccess information about the current scripting runtime host
属性PhysicsCall physics-related commands, and variables, such as raycasting
属性MathMath related functions (Sin, Cos, Tan, etc)
属性StringMiscellaneous additional string functions (e.g. MD5Sum)
属性InputInput device related functions (mouse position, keyboard state)
属性CameraTake and control the users camera
属性WebServicesCall remote web services to designated hosts (will not work with arbitrary domains, see page for details)
属性NetworkSend data to other clients through the region server
属性PostFX–
属性AudioAnalyser–
属性Tween–
属性UI–
属性Dialogues–
属性Shared–
属性Quests–
属性Economy–
属性Groups–
属性Activity–
属性RenderSettings–
属性Profile–
属性Photos–
属性Videos–
属性MusicDirectory–
属性Journey–
属性GameTester–
属性RuntimeTypeReturn current RuntimeType name.
属性PlatformReturn current platform name.
属性SessionIDReturn current SessionID.
属性InEditorReturn true if in unity editor.
属性VersionReturns the numeric build version of the viewer (for programmatic comparisons).
属性FullVersionStringReturns the full build version display string tied to release notes (e.g., "2025.6f210").
属性Resources–
属性TimeReturns time at the beginning of this frame.
属性ServerTimeReturns current server time.
属性LocalTimeReturns current local time.
属性LoginTimeReturns how long player has been logged in (in seconds).
属性ServerTimeUnixReturns the server time unix timestamp.
属性LocalTimeUnixReturns the local time unix timestamp.
属性DeltaTimeThe completion time in seconds since the last frame.
属性PreviewServerReturn true if in preview server.
属性ComponentNameThe name of this component.

函数​

TypeName​

string TypeName(DynValue dv)

Return the type name of the value.

参数

名称类型默认值
dvDynValue–

返回值

string

示例

Lua
typeName = Space.TypeName("123")

TrackingAllowed​

bool TrackingAllowed(string key)

Returns true on white-label grids when the user has opted into tracking for the given key. Always returns false on the main grid.

参数

参数类型说明
keystringA unique identifier used to store and look up the user's tracking consent.

返回值

bool

示例

Lua
isTrackingAllowed = Space.TrackingAllowed('3423423423423')

TrackingRequest​

void TrackingRequest(string key, string privacynotice, Closure callback, bool force = false)

Displays a consent prompt (EULA-style) asking the user to allow tracking for a given key. On white-label grids, stores the user's choice and invokes the callback with a boolean indicating consent. On the main grid, this does nothing.

参数

参数类型说明
keystringA unique identifier used to store and look up the user's tracking consent.
privacynoticestringThe privacy notice text to display in the consent dialog.
callbackClosureA function invoked with one boolean parameter: true if allowed, false otherwise.
forceboolIf true, show the prompt even if a stored decision exists. Defaults to false.

返回值

void

示例

Lua
-- Request consent (white-label only). The callback receives a boolean 'allowed'.
Space.TrackingRequest('24234234234234', 'A notice message', function(allowed)
if allowed then
Space.Log("Tracking allowed")
else
Space.Log("Tracking denied")
end
end)
-- or force re-prompt even if a decision was saved previously:
Space.TrackingRequest('24234234234234', 'A notice message', function(allowed) end, true)

GetResource​

SResource GetResource(string name)

Returns a reference to a SResource using it's Resource name.

参数

参数类型说明
namestringName of the Resource as set in the Scripting Runtime Component (Resources section)

返回值

SResource

示例

Lua
aResource = Space.GetResource("ResourceName")

LogEvent​

void LogEvent(string eventName, float value, SVector position)

Logs an analytics event to the server on white-label grids.

参数

参数类型说明
eventNamestringThe name of the analytics event.
valuefloatA numeric value associated with the event.
positionSVectorA world position to associate with the event.

返回值

void

示例

Lua
Space.LogEvent('event name', 2.0, Vector.New(0,0,0) )

Log​

void Log(DynValue text, bool logToFile = false)
void Log(string text, bool logToFile = false)

Log a message to console.

参数

名称类型默认值
textDynValue–
logToFileboolfalse
textstring–

返回值

void

示例

Lua
Space.Log(Color.Blue)
--or
Space.Log("Log")
--or
Space.Log("Log",true)

属性​

Inventory只读​

SInventory Inventory {get; }

Allows access to the users inventory

示例

Lua
inventory = Space.Inventory

Persistence只读​

SPersistence Persistence {get; }

Stores information between user sessions, and for other users

示例

``` persistence = Space.Persistence ```

Scene只读​

SScene Scene {get; }

Allows access to the current scene graph (objects and avatars in the scene, and other information)

示例

Lua
scene = Space.Scene

Grid只读​

SGrid Grid {get; }

示例

Lua
grid = Space.Grid

Host只读​

SHost Host {get; }

Access information about the current scripting runtime host

示例

Lua
host = Space.Host

Physics只读​

SPhysics Physics {get; }

Call physics-related commands, and variables, such as raycasting

示例

Lua
physics = Space.Physics

Math只读​

SMath Math {get; }

Math related functions (Sin, Cos, Tan, etc)

示例

Lua
Space.Math.Ceil(4.0)

String只读​

SString String {get; }

Miscellaneous additional string functions (e.g. MD5Sum)

示例

Lua
Space.String.GetBytes("some data")

Input只读​

SInput Input {get; }

Input device related functions (mouse position, keyboard state)

示例

Lua
Space.Input.Vibrate(1,1,false)

Camera只读​

SCameraManager Camera {get; }

Take and control the users camera

示例

Lua
obj = Space.Host.ExecutingObject
Space.Camera.LockCamera (obj)

WebServices只读​

SWebService WebServices {get; }

Call remote web services to designated hosts (will not work with arbitrary domains, see page for details)

示例

Lua
Space.WebServices.GetImage("example.com/mrlee.jpg")

Network只读​

SNetwork Network {get; }

Send data to other clients through the region server

示例

Lua
Space.Network.SubscribeToNetwork("helloworld", gotAMessageFunction)

PostFX只读​

SPostFX PostFX {get; }

示例

Lua
Space.PostFX

AudioAnalyser只读​

SAudioAnalyser AudioAnalyser {get; }

示例

Lua
Space.AudioAnalyser

Tween只读​

STween Tween {get; }

示例

Lua
Space.Tween

UI只读​

SUI UI {get; }

示例

Lua
ui = Space.UI

Dialogues只读​

SDialogues Dialogues {get; }

示例

Lua
dialogues = Space.Dialogues

Shared只读​

SShared Shared {get; }

示例

Lua
shared = Space.Shared

Quests只读​

SQuests Quests {get; }

示例

Lua
quests = Space.Quests

Economy只读​

SEconomy Economy {get; }

示例

Lua
economy = Space.Economy

Groups只读​

SGroup Groups {get; }

示例

Lua
groups = Space.Groups

Activity只读​

SActivity Activity {get; }

示例

``` activity = Space.Activity ```

RenderSettings只读​

SRenderSettings RenderSettings {get; }

示例

Lua
renderSettings = Space.RenderSettings

Profile只读​

SProfile Profile {get; }

示例

Lua
profile = Space.Profile

Photos只读​

SPhotos Photos {get; }

示例

Lua
photos = Space.Photos

Videos只读​

SVideos Videos {get; }

示例

Lua
videos = Space.Videos

MusicDirectory只读​

SMusicDirectory MusicDirectory {get; }

示例

Lua
musicDirectory = Space.MusicDirectory

Journey只读​

SJourney Journey {get; }

示例

Lua
journey = Space.Journey

GameTester只读​

SGameTester GameTester {get; }

示例

Lua
gameTester = Space.GameTester

RuntimeType只读​

string RuntimeType {get; }

Return current RuntimeType name.

示例

Lua
runtimeType = Space.RuntimeType

Platform只读​

string Platform {get; }

Return current platform name.

示例

Lua
platform = Space.Platform

SessionID只读​

string SessionID {get; }

Return current SessionID.

示例

Lua
sessionID = Space.SessionID

InEditor只读​

bool InEditor {get; }

Return true if in unity editor.

示例

Lua
isInEditor = Space.InEditor
Lua
--the below script checks if we are in Unity editor or in SS
--this way we can provide an alternative
--(Example: if we're using a function that doesn't work in Unity editor)

thisGameObject = Space.Host.ExecutingObject


if Space.InEditor then
avatarUsername = "Player Name"
else
avatarUsername = Space.Scene.GetAvatar(thisGameObject.Owner).Username --example: this doesn't work in Editor
end

Space.Log(avatarUsername)

Version只读​

int Version {get; }

Returns the numeric build version of the viewer (for programmatic comparisons). In the Unity Editor this returns int.MaxValue; if unknown at runtime it returns -1.

示例

Lua
viewerVersion = Space.Version

FullVersionString只读​

string FullVersionString {get; }

Returns the full build version display string tied to release notes (e.g., "2025.6f210"). Best for user-facing display and logging.

示例

Lua
viewerVersionString = Space.FullVersionString

Resources只读​

SResource[] Resources {get; }

示例

Lua
tableOfResources = Space.Resources
Lua
--the below script will search through the Scripting Runtime's resources
--and return the first instance of an Animation Clip
--[You need to add a few resources to the scripting runtime and make one of them an animation]


resources = Space.Resources

for i = 1, #resources do
if resources[i].Type == "AnimationClip" then
Space.Log("Resource #".. i .. " is an Animation Clip. The resource name is: " .. resources[i].Name)
break
end
end

Time只读​

float Time {get; }

Returns time at the beginning of this frame.

示例

Lua
floatTime = Space.Time
Lua
--this script will update a UIText object with the current local time without using a coroutine
--(example: clock )
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

rateUpdate = 1.0
nextUpdate = 0.0
text = Space.Host.GetReference("Text").UIText


OnUpdate = function()
if Space.Time > nextUpdate then
nextUpdate = Space.Time + rateUpdate
text.Text = Space.LocalTime
end
}

Space.Host.ExecutingObject.OnUpdate(OnUpdate)

ServerTime只读​

string ServerTime {get; }

Returns current server time.

示例

Lua
serverTime = Space.ServerTime
Lua
--this script will update a UIText object with the current server time (UTC)
--(example: clock)
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

text = Space.Host.GetReference("Text").UIText

co = function()
while true do
text.Text = Space.ServerTime
coroutine.yield(1)
end
end

Space.Host.StartCoroutine(co)

LocalTime只读​

string LocalTime {get; }

Returns current local time.

示例

Lua
localTime = Space.LocalTime
Lua
--this script will update a UIText object with the current local time
--(example: clock)
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

text = Space.Host.GetReference("Text").UIText

co = function()
while true do
text.Text = Space.LocalTime
coroutine.yield(1)
end
end

Space.Host.StartCoroutine(co)

LoginTime只读​

float LoginTime {get; }

Returns how long player has been logged in (in seconds).

示例

Lua
loginTime = Space.LoginTime
Lua
--this script will update a UIText object with how long the user has been logged in (in seconds)
--(example: clock)
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

text = Space.Host.GetReference("Text").UIText

co = function()
while true do
text.Text = Space.LoginTime
coroutine.yield(1)
end
end

Space.Host.StartCoroutine(co)

ServerTimeUnix只读​

int ServerTimeUnix {get; }

Returns the server time unix timestamp.

示例

Lua
serverTimeUnix = Space.ServerTimeUnix
Lua
--this script will update a UIText object with the current server time unix timestamp
--(example: clock)
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

text = Space.Host.GetReference("Text").UIText

co = function()
while true do
text.Text = Space.ServerTimeUnix
coroutine.yield(1)
end
end

Space.Host.StartCoroutine(co)

LocalTimeUnix只读​

int LocalTimeUnix {get; }

Returns the local time unix timestamp.

示例

Lua
localTimeUnix = Space.LocalTimeUnix
Lua
--this script will update a UIText object with the current local time unix timestamp
--(example: clock)
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

text = Space.Host.GetReference("Text").UIText

co = function()
while true do
text.Text = Space.LocalTimeUnix
coroutine.yield(1)
end
end

Space.Host.StartCoroutine(co)

DeltaTime只读​

float DeltaTime {get; }

The completion time in seconds since the last frame.

示例

Lua
deltaTime = Space.DeltaTime
Lua
--the below script rotates an object around Y axis but uses DeltaTime
--to make sure it's not dependant on client's Framerate (FPS)
--this way the object rotates per second not per frame
--(Example: Important movement in OnUpdate)

thisGameObject = Space.Host.ExecutingObject



OnUpdate = function()
currentY = thisGameObject.WorldRotation.EulerAngles.Y
newRotation = Quaternion.Euler(0, currentY + 1 * Space.DeltaTime, 0) --We multiplied 1 by Space.DeltaTime
thisGameObject.WorldRotation = newRotation
end

thisGameObject.OnUpdate(OnUpdate)

PreviewServer只读​

bool PreviewServer {get; }

Return true if in preview server.

示例

Lua
isInPreview = Space.PreviewServer
Lua
--this script will update a UIText object with "preview" or "live" depending
--whether we are on preview server or live server
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]

text = Space.Host.GetReference("Text").UIText

OnUpdate = function()
if Space.PreviewServer then
text.Text = "Preview"
else
text.Text = "Live"
end
end

Space.Host.ExecutingObject.OnUpdate(OnUpdate)

ComponentName只读​

string ComponentName {get; }

The name of this component.

示例

Lua
componentName = Space.ComponentName