GuiService

显示已弃用

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

无法创建
服务
未复制

GuiService 允许开发人员控制游戏手柄导航器目前选择了什么 GuiObject,以及检查 Roblox 的主菜单目前是否打开。

概要

属性

方法

活动

属性

AutoSelectGuiEnabled

读取并联

激活后,游戏手柄或 Backslash 上的 Select 按钮将自动将 GUI 设置为选定对象。关闭此功能将意味着如果启用了 GuiService.GuiNavigationEnabled,GUI 导航仍然可以工作,但您必须手动设置 GuiService.SelectedObject 才能启动 GUI 导航。

CoreGuiNavigationEnabled

隐藏
未复制
读取并联

切换是否使用游戏手柄导航 CoreGui 中的对象。

GuiNavigationEnabled

读取并联

用于启用和禁用默认控制器图形用户界面导航。

只读
未复制
读取并联

如果任何 CoreGui 菜单打开,返回真值。

PreferredTextSize

只读
未复制
读取并联

PreferredTransparency

隐藏
只读
未复制
读取并联

获取用户的首选透明度为 0 到 1 之间的数字,该数字表示用户想要让 UI 元素背景变得多暗。默认为 1。

此返回值反映了可以从应用设置或经验设置菜单中设置的设置,也可以通过 背景透明 从用户那里设置。默认值为 1,表示用户更喜欢默认背景透明度。最低值为 0,表示用户更喜欢将背景完全不透明,提高受影响的 UI 的可读性和对比度。将元素的 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 事件改变。

如果您想确定此属性何时更改而不跟踪所有图形用户界面元素的选择获得和选择丢失事件,您可以使用 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

读取并联

用于启用和禁用触摸控制和触摸控制显示界面。默认为 true。

方法

CloseInspectMenu

()

此函数关闭检查菜单,如果打开,在从 LocalScript 运行时。

还见:


返回

()

DismissNotification

参数

notificationId: string
默认值:""

返回

GetEmotesMenuOpen

返回一个 boolean,表示玩家表情菜单是否打开。

开发者可以通过调用 GuiService:SetEmotesMenuOpen() 函数打开或关闭表情菜单。


返回

指示是否打开表情菜单。

GetGameplayPausedNotificationEnabled

该函数返回是否 gameplay paused 通知已被开发者禁用。

开发者可以通过调用 GuiService:SetGameplayPausedNotificationEnabled() 函数启用或禁用通知。

还见:


返回

是否禁用了 gameplay paused 通知。

GetGuiInset

返回两个 Vector2 值,分别代表屏幕左上角和屏幕右下角的用户图形界面插入值。

由此函数提供的插入值仅对 ScreenGuis 有效,其 IgnoreGuiInset 属性设置为 false。


返回

描述当前指定 Gui 插入的两个 Vector2 值的 tuple。

GetInspectMenuEnabled

该函数返回是否启用了检查和购买菜单功能。功能默认启用,并且可以使用 GuiService:SetInspectMenuEnabled() 函数进行设置。

还见:


返回

一个 bool 指示是否启用检查菜单功能。

InspectPlayerFromHumanoidDescription

()

这个函数允许开发人员打开检查菜单,显示列出在这个 HumanoidDescription 对象中的资产。

这允许进一步自定义与玩家在游戏中检查其他玩家所显示的内容。如果你的游戏修改了玩家穿着的内容,你可以给检查菜单一个 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 的用户界面的特殊版本,仅限于控制台,返回真实值。这是验证用户是否在控制器上的唯一保证方法。


返回

Select

()

当在实例选择父中调用选择时,引擎搜索所有可用的可选、可见和在屏幕上的 GuiObject,这些都是选择父的子孙,并将 GuiService.SelectedObject 设置为具有最小 GuiService.SelectionOrder 的 GuiObject。

参数

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

()

这种方法允许开发人员在玩家游戏暂停时禁用内置通知。他们可以添加自己的 UI,如果他们希望自定义它。

开发者可以通过调用 GuiService:GetGameplayPausedNotificationEnabled() 函数查询是否启用通知。

还见:

参数

enabled: boolean

是否禁用内置通知图形用户界面。

默认值:""

返回

()

SetInspectMenuEnabled

()

该函数允许开发人员启用或禁用默认的检查和购买功能。当您想禁用游戏中的功能(全部或在特定部分)时,这很有用。例如,切场镜头。该功能默认启用。

以下代码示例显示了如何为您的游戏禁用检查菜单:


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

还见:

参数

enabled: boolean

一个 bool 指示是否启用或禁用检查菜单精选能。

默认值:""

返回

()

活动

当用户 关闭 Roblox核心图形用户界面逃生菜单时发生火灾。


当用户 打开 Roblox核心图形用户界面逃生菜单时,发生火灾。