StudioService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务
未复制

工作室服务 提供访问 Roblox Studio 的配置,允许从用户的文件系统导入文件,以及其他杂项信息。它是用于由 Plugins 使用的,以提供一致的用户体验。

概要

属性

方法

属性

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

只读
未复制
读取并联

GridSize

只读
未复制
读取并联

网格大小 决定工作室拖动和移动工具每次移动对象的距离,以学分为单位。这在用户的工具栏的 模型 选项卡中设置。

RotateIncrement

只读
未复制
读取并联

旋转增量 决定 Studio 的旋转工具每次旋转选定对象的角度以度。这在用户的工具栏的 模型 选项卡中设置。

Secrets

Roblox 脚本安全性
读取并联

ShowConstraintDetails

只读
未复制
读取并联

ShowWeldDetails

只读
未复制
Roblox 脚本安全性
读取并联

StudioLocaleId

只读
未复制
读取并联

StudioLocaleId 属性包含 Studio 目前使用的本地,例如 en_US。在本地化插件时有用。

以下是基于此函数返回的值的本地化示例。


local locale = game:GetService("StudioService").StudioLocaleId
if locale == "en_US" then
print("Howdy, ya'll")
elseif locale == "en_GB" then
print("'Ello, gov'na")
elseif locale:sub(1, 2) == "en" then
print("Hello")
elseif locale == "fr_FR" then
print("Bonjour")
end

UseLocalSpace

未复制
读取并联

使用本地空间 决定Studio移动/旋转工具是否使用对象的本地空间或全球空间来操纵零件的CFrame。默认情况下,这个设置与 Ctrl L L 切换。插件可以阅读此属性,如果它们实现了自己的对象移动工具。

方法

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")

参数

className: string
默认值:""

返回

GetUserId

插件安全性

如果用户已登录,返回工作室用户的 uuid;如果没有登录,则返回 0。


返回

代码示例

The example prints the currently logged in user's ID.

StudioService:GetUserId

-- 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

插件安全性

参数

origin: Vector3
默认值:""
direction: Vector3
默认值:""
raycastParams: RaycastParams
默认值:"RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

返回

PromptImportFile

暂停
插件安全性

该函数提示当前工作室用户选择一个文件,该文件将被加载为 File

还见:

参数

fileTypeFilter: Array

用户可以选择的文件类型列表。文件类型没有使用时间格式化。例如,"jpg"、"png"仅允许选择 JPG 或 PNG 文件。如果没有提供过滤器,过滤器是 nil 并允许用户选择任何文件输入。

默认值:"{}"

返回

导入的 File 。如果没有选择文件,或选定的文件太大(文件大小超过 100 兆字节),将返回 nil

PromptImportFiles

Instances
暂停
插件安全性

此函数提示当前工作室用户选择一个或多个文件,然后将其加载为 Files

如果 fileTypeFilter 是空列表,将抛出错误。

还见:

参数

fileTypeFilter: Array

用户可以选择的文件类型列表。文件类型没有使用时间格式化。例如,"jpg"、"png"仅允许选择 JPG 和 PNG 文件。如果没有提供过滤器,过滤器是 nil 并允许用户选择任何文件输入。

默认值:"{}"

返回

Instances

导入的 Files 。如果没有选择文件,返回一个空列表。返回 nil 如果用户选择了一个或多个太大的文件(文件大小超过 100 兆字节)。

活动