GuiService

顯示已棄用項目

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

無法建立
服務
未複製

GuiService 允許開發人員控制遊戲手柄瀏覽器目前選擇了什麼 GuiObject,以及檢查 Roblox 的主選單目前是否開啟。

概要

屬性

方法

活動

屬性

AutoSelectGuiEnabled

平行讀取

啟用後,遊戲控制器上的 Select 按鈕或 Backslash 將自動設置 GUI 為選擇的對物件。關閉此選項會意味著如果 GuiService.GuiNavigationEnabled 啟用,GUI 導航仍然會工作,但您必須手動設置 GuiService.SelectedObject 才能開始 GUI 導航。

CoreGuiNavigationEnabled

隱藏
未複製
平行讀取

切換是否使用遊戲手柄導航 CoreGui 中的物件。

GuiNavigationEnabled

平行讀取

用於啟用和禁用預設控制器GUI導航。

唯讀
未複製
平行讀取

如果任何 CoreGui 菜單打開,返回真值。

PreferredTextSize

唯讀
未複製
平行讀取

PreferredTransparency

隱藏
唯讀
未複製
平行讀取

獲得使用者的首選透明度為 0 到 1 之間的數字,表示他們想要將 UI 元素背景透明度設為多少。預設值為 1。

此返回值反映了可以從應用程式設定或經驗設定選單中設定的設定,或透過 背景透明 從使用者那裡設定的設定。預設值為 1,表示使用者喜歡預設背景透明度。最低值為 0,表示使用者喜歡將背景完全不透明,提高對受影響的介面的可讀性和對比。將元素的 GuiObject.BackgroundTransparency 乘以從 PreferredTransparency 返回的值是使用此設置的建議方式;背景將在 PreferredTransparency 接近 0 時變得更不透明。這應該與 Object:GetPropertyChangedSignal() 一起使用,以便在使用者變更首選透明度時自動更新。

範例程式碼

Uses the user's value for GuiService.PreferredTransparency by combining it with the desired default background transparency. Also automatically updates the background transparency whenever the user changes their preferred transparency.

Use Preferred Transparency

local DEFAULT_TRANSPARENCY = 0.5
local frame = script.Parent
local function setBackgroundTransparency()
frame.BackgroundTransparency = DEFAULT_TRANSPARENCY * GuiService.PreferredTransparency
end
GuiService:GetPropertyChangedSignal("PreferredTransparency"):Connect(setBackgroundTransparency)
setBackgroundTransparency()

ReducedMotionEnabled

隱藏
唯讀
未複製
平行讀取

如果使用者啟用了減少運動,返回 true ;如果未啟用,則返回 false

此返回值反映了可以從應用程式設定或經驗設定選單中設定的設定,該設定可以透過 減少運動 從使用者那裡設定。值 true 表示使用者希望減少或完全移除運動效果和動畫。

範例程式碼

Uses the user's value for GuiService.ReducedMotionEnabled by instantly transitioning the frame instead of animating it, if the value of Reduced Motion is true.

Use Reduced Motion

local DEFAULT_TRANSPARENCY = 0.5
local frame = script.Parent
local endPosition = UDim2.fromScale(0.5, 0.8)
if GuiService.ReducedMotionEnabled then
frame.Position = endPosition
else
local moveTweenInfo = TweenInfo.new(0.5)
local moveTweenProps = {
Position = endPosition,
}
local moveTween = TweenService:Create(frame, slideInTweenInfo, slideInTweenProps)
moveTween:Play()
end

SelectedObject

平行讀取

設置目前由 GUI 導航器 (用於遊戲板) 聚焦的 GuiObject 。如果對象處於畫面外,可能會重設為 nil

此屬性由 GuiObject.SelectionGainedGuiObject.SelectionLost 事件變更。

如果您想確定此屬性何時更改,而不跟蹤所有 GUI 元素的選擇獲得和選擇損失事件,您可以使用 Changed 事件。

範例程式碼

The code below demonstrates how to handle when the SelectedObject changes. For instance, this event fires when the Gamepad navigates to another GUI element.

Printing When Gamepad Selection Changes

local GuiService = game:GetService("GuiService")
local function printChanged(value)
if value == "SelectedObject" then
print("The SelectedObject changed!")
end
end
GuiService.Changed:Connect(printChanged)

TopbarInset

唯讀
未複製
平行讀取

返回 Rect 對象,代表 Roblox 最左控制和裝置安全區邊緣之間的空置區域。

值是動態的,可以根據 UI 控件的可見度(例如更改本地玩家的 Health 屬性、使用 StarterGui:SetCoreGuiEnabled() 或變更 Roblox UI 控制的大小和位置等)而變化。因此,建議您使用 Object:GetPropertyChangedSignal() 偵測並回應此屬性的變更。

範例程式碼

This code snippet creates a new ScreenGui with a Frame that automatically adapts its size and position to a top bar space unoccupied by Roblox UI.

Responsive Frame Within Available Top Bar Space

local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = Players.LocalPlayer.PlayerGui
local frame = Instance.new("Frame")
frame.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
frame.Parent = screenGui
GuiService:GetPropertyChangedSignal("TopbarInset"):Connect(function()
local inset = GuiService.TopbarInset
frame.Size = UDim2.new(0, inset.Width, 0, inset.Height)
frame.Position = UDim2.new(0, inset.Min.X, 0, inset.Min.Y)
end)

TouchControlsEnabled

平行讀取

用於啟用和禁用觸控控制和觸控控制顯示介面。默認為真。

方法

CloseInspectMenu

()

此功能會在從 LocalScript 執行時關閉檢查選單,如果開啟,當開啟時。

也見:


返回

()

DismissNotification

參數

notificationId: string
預設值:""

返回

GetEmotesMenuOpen

返回是否打開玩家表情選單的 boolean 值。

開發人員可以透過呼叫 GuiService:SetEmotesMenuOpen() 函數來開啟或關閉表情選單。


返回

指示是否打開表情選單。

GetGameplayPausedNotificationEnabled

此功能返回是否 gameplay paused 通知已被開發者禁用。

開發人員可以通過呼叫 GuiService:SetGameplayPausedNotificationEnabled() 函數來啟用或禁用通知。

也見:


返回

無論是否已停用 gameplay paused 通知。

GetGuiInset

返回兩個 Vector2 值,分別代表屏幕左上角和屏幕右下角的用戶圖形介面插入,從屏幕的左上角和屏幕右下角分別。

這個函數提供的插入值只在 ScreenGuis 上生效,其 IgnoreGuiInset 屬性設為 false。


返回

一個包含兩個 Vector2 值的陣列,用於描述當前指定的 Gui 插入。

GetInspectMenuEnabled

此功能返回是否啟用檢查和購買菜單功能。功能預設啟用,並可使用 GuiService:SetInspectMenuEnabled() 函數設置。

也見:


返回

一個指示是否啟用檢查選單功能的 boolean 值。

InspectPlayerFromHumanoidDescription

()

此功能允許開發人員帶起檢查選單,顯示列出在此 HumanoidDescription 物件象中的資產。

這樣可以進一步自訂玩家在遊戲中檢查其他玩家時所顯示的內容。如果您的遊戲修改玩家穿著的內容,您可以將玩家穿著的內容轉換為人形描述對象,並顯示這些項目。您應該傳送一個名稱來代表要檢查的玩家的名稱。

也見:

參數

humanoidDescription: Instance

包含在檢查選單中顯示的資產的 HumanoidDescription 對象。

預設值:""
name: string

正在檢查顯示在檢查選單中的玩家名稱。

預設值:""

返回

()

範例程式碼

This example demonstrates how to show an Inspect Menu containing two items (Midnight Antlers and Mid-Summer Starry Wings), for a player named MyPlayer using GuiService:InspectPlayerFromHumanoidDescription.

Opening an Inspect Menu with a HumanoidDescription

local GuiService = game:GetService("GuiService")
local humanoidDescription = Instance.new("HumanoidDescription")
humanoidDescription.HatAccessory = "3339374070"
humanoidDescription.BackAccessory = "3339363671"
GuiService:InspectPlayerFromHumanoidDescription(humanoidDescription, "MyPlayer")

InspectPlayerFromUserId

()

此功能允許檢查選單出現,向用戶顯示擁有指定 UserId 的用戶。這特別適用於當您想檢查不在當前遊戲中的玩家時。

這會顯示與指定使用者個人檔案上的「目前穿著」標籤相同的資訊。

也見:

參數

userId: number

要檢查的玩家的 UserId

預設值:""

返回

()

範例程式碼

The code sample below demonstrates how to use GuiService:InspectPlayerFromUserId() to open the Inspect Menu for the Roblox user with the id 772462.

Opening the Inspect Menu for a UserId

local GuiService = game:GetService("GuiService")
GuiService:InspectPlayerFromUserId(772462)

IsTenFootInterface

如果客戶使用了十英尺界面,這是 Roblox 的 UI 的特殊版本,僅適用於控制台,則返回真值。這是唯一一種保證方式來確認使用者是否在控制台上。


返回

Select

()

當在實例選擇Parent中呼叫選擇時,引擎搜尋所有可選擇、可視和在螢幕上的Gui對象,這些對象是選擇Parent的子孫或其子孫,並將 設為最小子孫的Gui對象。

參數

selectionParent: Instance

搜尋其子孫的選擇的父親。

預設值:""

返回

()

範例程式碼

Uses the user's value for GuiService.PreferredTransparency by combining it with the desired default background transparency. Also automatically updates the background transparency whenever the user changes their preferred transparency.

Use Preferred Transparency

local DEFAULT_TRANSPARENCY = 0.5
local frame = script.Parent
local function setBackgroundTransparency()
frame.BackgroundTransparency = DEFAULT_TRANSPARENCY * GuiService.PreferredTransparency
end
GuiService:GetPropertyChangedSignal("PreferredTransparency"):Connect(setBackgroundTransparency)
setBackgroundTransparency()

SendNotification

參數

notificationInfo: Dictionary
預設值:""

返回

SetEmotesMenuOpen

()

開啟或關閉玩家表情選單。

參數

isOpen: boolean
預設值:""

返回

()

SetGameplayPausedNotificationEnabled

()

這個方法讓開發人員在玩家遊戲暫停時禁用內建通知。他們可以添加自己的用戶介面,如果他們希望自定義它。

開發人員可以透過呼叫 GuiService:GetGameplayPausedNotificationEnabled() 函數查詢是否啟用通知。

也見:

參數

enabled: boolean

是否禁用內置通知GUI。

預設值:""

返回

()

SetInspectMenuEnabled

()

此功能讓開發人員啟用或停用預設檢查和購買功能。當您想停用遊戲中的功能時(例如在特定部分或全部遊戲中),這很有用。功能預設啟用。

以下代碼示範如何為您的遊戲停用檢查選單:


local GuiService = game:GetService("GuiService")
GuiService:SetInspectMenuEnabled(false)

也見:

參數

enabled: boolean

一個是否指示啟用或禁用檢查選單功能的 boolean 值。

預設值:""

返回

()

活動

當使用者 關閉 Roblox核心GUI逃生選單時發生火災。


當使用者 開啟 Roblox核心GUI逃生選單時,發生火災。