工作室服务 提供访问 Roblox Studio 的配置,允许从用户的文件系统导入文件,以及其他杂项信息。它是用于由 Plugins 使用的,以提供一致的用户体验。
- 显示实例类别图标的插件可以使用 GetClassIcon。
- 关心哪个脚本正在编辑中的插件(如果有)可以从 ActiveScript 阅读此内容。
概要
属性
反映当前正在编辑的 LuaSourceContainer (如果有)。
决定工作室拖动和移动工具每次移动对象的距离(以螺柱为单位)。
决定工作室的旋转工具每次旋转选定对象的度数。
Studio 目前使用的本地,例如 en_US .
决定工作室工具是否使用对象的本地空间或全球空间。
方法
属性
ActiveScript
ActiveScript 指的是当前由用户编辑的 LuaSourceContainer。如果用户未编辑脚本,这将是 nil 。以下是一个示例,显示您如何使用此属性来测量脚本是否长时间运行。
local StudioService = game:GetService("StudioService")
local startTime = os.time()
local activeScript
local function onActiveScriptChanged()
local newActiveScript = StudioService.ActiveScript
if activeScript and newActiveScript ~= activeScript then
local deltaTime = os.time() - startTime
print(("You edited %s for %d:%2.d"):format(activeScript.Name, deltaTime // 60, deltaTime % 60))
end
startTime = os.time()
activeScript = newActiveScript
end
StudioService:GetPropertyChangedSignal("ActiveScript"):Connect(onActiveScriptChanged)
DraggerSolveConstraints
Secrets
ShowConstraintDetails
ShowWeldDetails
StudioLocaleId
StudioLocaleId 属性包含 Studio 目前使用的本地,例如 en_US。在本地化插件时有用。
以下是基于此函数返回的值的本地化示例。
local locale = game:GetService("StudioService").StudioLocaleIdif locale == "en_US" thenprint("Howdy, ya'll")elseif locale == "en_GB" thenprint("'Ello, gov'na")elseif locale:sub(1, 2) == "en" thenprint("Hello")elseif locale == "fr_FR" thenprint("Bonjour")end
方法
GetClassIcon
GetClassIcon 提供一个词典,可以显示类的 Explorer 窗口标志,例如调用此函数与“零件”返回显示从 Explorer 窗口显示零件图标的属性值。
以下是使用 "Part" 调用此函数时返回的值的字面表示。
{Image = "rbxasset://textures/ClassImages.png",ImageRectOffset = Vector2.new(16, 0),ImageRectSize = Vector2.new(16, 16)}
下面的实用函数可能在显示类图标时有用:
local StudioService = game:GetService("StudioService")
local imageLabel = script.Parent
local function displayClassIcon(image, className)
for k, v in StudioService:GetClassIcon(className) do
image[k] = v -- 设置属性
end
end
displayClassIcon(imageLabel, "Part")
参数
返回
GetUserId
如果用户已登录,返回工作室用户的 uuid;如果没有登录,则返回 0。
返回
代码示例
The example prints the currently logged in user's ID.
-- Can only be used in a plugin
local StudioService = game:GetService("StudioService")
local Players = game:GetService("Players")
local loggedInUserId = StudioService:GetUserId()
local loggedInUserName = Players:GetNameFromUserIdAsync(loggedInUserId)
print("Hello,", loggedInUserName)
GizmoRaycast
参数
返回
PromptImportFile
该函数提示当前工作室用户选择一个文件,该文件将被加载为 File 。
还见:
- StudioService:PromptImportFiles() , 同一个函数,但用于加载列表文件而不是单个文件
参数
用户可以选择的文件类型列表。文件类型没有使用时间格式化。例如,"jpg"、"png"仅允许选择 JPG 或 PNG 文件。如果没有提供过滤器,过滤器是 nil 并允许用户选择任何文件输入。
返回
PromptImportFiles
此函数提示当前工作室用户选择一个或多个文件,然后将其加载为 Files 。
如果 fileTypeFilter 是空列表,将抛出错误。
还见:
- StudioService:PromptImportFile() , 相同的函数,但用于加载单个文件而不是列表的文件
参数
用户可以选择的文件类型列表。文件类型没有使用时间格式化。例如,"jpg"、"png"仅允许选择 JPG 和 PNG 文件。如果没有提供过滤器,过滤器是 nil 并允许用户选择任何文件输入。
返回
导入的 Files 。如果没有选择文件,返回一个空列表。返回 nil 如果用户选择了一个或多个太大的文件(文件大小超过 100 兆字节)。