GuiBase2d

显示已弃用

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

无法创建
不可浏览

GUIBase2d 是 2D GUI 对象的抽象类。

概要

属性

活动

属性

AbsolutePosition

只读
未复制

绝对位置是一个只读的属性,它提供屏幕位置的UI元素在像素中的实际位置。这代表元素在其父元的大小和位置的结果下渲染为结果。GuiObject.AnchorPoint 还影响GuiBase2d.AbsoluteSize 和Class.GuiBase2d.Absolute

例如,在 1920 x 1080 屏幕上,一个 Frame 用位置 0.5,0,0.5,0 将有一个绝对位置(960,540)。如果您将另一个框放在那个位置 0,5

代码示例

This code sample shows how a UI element's size, position and rotation can be copied without parenting a "copycat" to the original. It uses the Absolute-family of properties to orient a "copycat" Frame that covers on the screen space that the original does.

Copycat Frame

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent
-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")
-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(0.5, 0.5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White
-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0)
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation
-- Insert into ancestor ScreenGui
copycat.Parent = screenGui

AbsoluteRotation

只读
未复制

绝对旋转是一个只读的属性,描述 UI 元素的实际屏幕旋转度。此属性, GuiBase2d.AbsoluteSizeGuiBase2d.AbsolutePosition 是所有属性的组,描

例如,如果 FrameA 有 40 度的旋转,而 FrameB 在其中有 50 度的 GuiObject.Rotation ,那么 FrameB 的绝对旋转将是 90 度。

代码示例

This code sample shows how a UI element's size, position and rotation can be copied without parenting a "copycat" to the original. It uses the Absolute-family of properties to orient a "copycat" Frame that covers on the screen space that the original does.

Copycat Frame

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent
-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")
-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(0.5, 0.5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White
-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0)
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation
-- Insert into ancestor ScreenGui
copycat.Parent = screenGui

AbsoluteSize

只读
未复制

绝对大小是一个只读的属性,它提供屏幕大小的 UI 元素在像素中的实际大小。这表示元素在其父元的大小结果下渲染为结果。此属性, GuiBase2d.AbsolutePositionGuiBase2d.AbsoluteRotation 是一个组合属性, 它们描述元素最终渲染方向的所有属性。

例如,在 1920 x 1080 屏幕上,如果 FrameA 存在于 FrameB 中,且他们都有 .5 大小,0 大小,0

代码示例

This code sample shows how a UI element's size, position and rotation can be copied without parenting a "copycat" to the original. It uses the Absolute-family of properties to orient a "copycat" Frame that covers on the screen space that the original does.

Copycat Frame

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent
-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")
-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(0.5, 0.5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White
-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0)
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation
-- Insert into ancestor ScreenGui
copycat.Parent = screenGui

AutoLocalize

读取并联

设置为 true 时,本地化将适用于此 GuiBase2d 和它的子辈。 使用本地化的入口是 LocalizationService:GetTableEntries() 返回的同一集。 启用 GuiBase2d.AutoLocalize 的入口将在必要时自动重新翻译云表后。

还请参阅 GuiBase2d.RootLocalizationTable

RootLocalizationTable

读取并联

一个引用 LocalizationTable 用于应用自动本地化到此 GuiBase2d 和它的子代。

Class.GuiBase2d.AutoLocalize 属性必须设置为 true 在此对象和其父对象上,才能应用自动本地化。您可以将其设置为在数据模型中的任何地方的 本地

如果在参考表中没有可用的翻译,它将在该表的父级中寻找翻译,如果它还是一个本地化表,等等。

还参阅 LocalizationService:GetTableEntries() 以及 GuiBase2d.RootLocalizationTable ,这些都解释了如何使用 Class.GuiBase2d.RootLocalizationTable 自动本地化。

SelectionBehaviorDown

读取并联

在下向方向中自定义游戏手柄选择行为。

SelectionBehaviorLeft

读取并联

在左向向选择游戏手柄的行为进行自定义。

SelectionBehaviorRight

读取并联

自定义游戏手柄选择行为在正确的方向。

SelectionBehaviorUp

读取并联

在上向方向中自定义游戏手柄选择行为。

SelectionGroup

读取并联

切换选择组以启用GUI的自定义选择游戏手柄的方式可以移动在按钮之间,这些是选择群组的后代,离开组,选择其他按钮。设置选择组为 true

方法

活动

SelectionChanged

这个事件会触发,当连接的 GuiBase2d 的任何子集中的选择发生变更时。 当选择高亮移动到一个 GuiObject 时,该 GuiObject 的泡泡会向所有上下游戏中的祖先发出,通知他们选择已更改/进入/退出到他们的子树下的 GuiObject。

参数

amISelected: bool

如果新选择与附加的 GuiBase2d 一致,则为 true。

previousSelection: GuiObject
newSelection: GuiObject

代码示例

This example shows how to use GuiBase2d.SelectionChanged to set the color of a background frame depending on if the gamepad selection has a child GuiObject focused in a hierarchy that looks like this:

You can add code to change the background color of backgroundWindow to green when buttons 1, 2 or 3 are selected and change to red when other buttons outside the frame are selected. This helps you to add any new buttons to the backgroundWindow without updating the code.

SelectionChanged Background Color

local backgroundWindow = script.Parent.BackgroundWindow
local function selectionChanged(isSelfSelected, previousSelection, newSelection)
if newSelection and newSelection:IsDescendantOf(backgroundWindow) then
backgroundWindow.BackgroundColor3 = Color3.new(0, 1, 0)
else
backgroundWindow.BackgroundColor3 = Color3.new(1, 0, 0)
end
end
backgroundWindow.SelectionChanged:Connect(selectionChanged)