StudioService 提供進入 Roblox Studio 的配置,允許從使用者的檔案系統中匯入檔案,以及其他雜項資訊。它是用於由 Plugins 提供一致的使用者體驗的。
- 顯示實例類別圖示的插件可以使用 GetClassIcon 。
- 關心哪個腳本正在編輯中(如果有)的插件可以從 ActiveScript 閱讀此內容。
概要
屬性
反映目前正在編輯的 LuaSourceContainer (如果有)。
決定工作室的拖動和移動工具每次點擊移動對象的距離,以學分為單位。
決定 Studio 的旋轉工具每次旋轉選擇的對象的度數。
Studio 目前使用的本地,例如 en_US 。
決定 Studio 工具是否使用對象的本地空間或全球空間。
方法
屬性
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
取得類別圖示 提供一個字典,可以顯示類別 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
如果使用者登入,返回工作室用戶的使用者ID;否則返回 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
此功能會提示現有的 Studio 使用者選擇一個檔案,然後將其載入為 File 。
也見:
- StudioService:PromptImportFiles() , 相同的功能,但用於載入一個列表的文件而不是單一文件
參數
使用者可選擇的檔案類型清單。檔案類型沒有使用週期格式化。例如,"jpg"、"png"僅允許選擇 JPG 或 PNG 文件。如果沒有過濾器提供,過濾器是 nil 並允許用戶選擇任何文件輸入。
返回
PromptImportFiles
此功能會提示現有的 Studio 使用者選擇一個或多個檔案,然後將其載入為 Files 。
如果 fileTypeFilter 是空白列表,則會發出錯誤。
也見:
- StudioService:PromptImportFile() , 相同的功能,但用於載入單個文件而不是一個列表的文件
參數
使用者可選擇的檔案類型清單。檔案類型沒有使用週期格式化。例如,"jpg"、"png"僅允許選擇 JPG 和 PNG 文件。如果沒有過濾器提供,過濾器是 nil 並允許用戶選擇任何文件輸入。
返回
進口的 Files 。如果沒有選擇文件,返回空白列表。如果使用者選擇了一個或多個過大的檔案(檔案大小超過100MB),將返回nil 。