StudioService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務
未複製

StudioService 提供進入 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

唯讀
未複製
平行讀取

網格尺寸 決定 Studio 的拖動和移動工具每次點擊移動對象的距離,以點為單位。這在使用者的工具欄的 模型 標籤中設定。

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

外掛程式安全性

取得類別圖示 提供一個字典,可以顯示類別 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

外掛程式安全性

如果使用者登入,返回工作室用戶的使用者ID;否則返回 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

暫停
外掛程式安全性

此功能會提示現有的 Studio 使用者選擇一個檔案,然後將其載入為 File

也見:

參數

fileTypeFilter: Array

使用者可選擇的檔案類型清單。檔案類型沒有使用週期格式化。例如,"jpg"、"png"僅允許選擇 JPG 或 PNG 文件。如果沒有過濾器提供,過濾器是 nil 並允許用戶選擇任何文件輸入。

預設值:"{}"

返回

导入的 File 。如果未選擇文件,或選擇的文件過大(FileSize大於 100 兆字節),將返回 nil

PromptImportFiles

Instances
暫停
外掛程式安全性

此功能會提示現有的 Studio 使用者選擇一個或多個檔案,然後將其載入為 Files

如果 fileTypeFilter 是空白列表,則會發出錯誤。

也見:

參數

fileTypeFilter: Array

使用者可選擇的檔案類型清單。檔案類型沒有使用週期格式化。例如,"jpg"、"png"僅允許選擇 JPG 和 PNG 文件。如果沒有過濾器提供,過濾器是 nil 並允許用戶選擇任何文件輸入。

預設值:"{}"

返回

Instances

進口的 Files 。如果沒有選擇文件,返回空白列表。如果使用者選擇了一個或多個過大的檔案(檔案大小超過100MB),將返回nil

活動