GUIBase2d 是 2D GUI 對象的継承抽象類。
概要
屬性
描述介面元素的實際屏幕位置,以幣晃。
描述 UI 元素的實際螢幕旋轉度。
描述 UI 元素的實際屏幕尺寸,以幣晃。
設為真的時,本地化將適用於此 GuiBase2d 和它的後代。
一個引用 LocalizationTable 以應用自動本地化到這個 GuiBase2d 和它的後代。
在下向方向中自訂遊戲控制器選擇行為。
在左向方向中自訂遊戲控制器選擇行為。
自訂遊戲控制器選擇行為。
在上方向中自訂遊戲控制器選擇行為。
允許自訂遊戲控制器選擇動作。
活動
- SelectionChanged(amISelected : bool,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
發射在遊戲控制器選擇移動到,離開,或變更連接的 GuiBase2d 或任何子選項 GuiObjects。
屬性
AbsolutePosition
絕對位置是一個只讀取的屬性,它提供一個元素在畫素的位置。這代表元素在繼承的尺寸和位置的結果。 GuiObject.AnchorPoint 也代表絕對位置。這個屬性, Class.GuiBase2d.AbsoluteSize
舉例來說,在一個 1920 由 1080 畫面上,一個 Frame 用位置 0.5,0,0.5,0 將有一個絕對位置 (960, 540)。如果
範例程式碼
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.
-- 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
AbsoluteRotation 是一個只能閱取的屬性,描述介面元素的實際旋轉角度。這個屬性, GuiBase2d.AbsoluteSize 和 Class.GuiBase2d.AbsolutePosition</
例如,如果 FrameA 的旋轉是 40 度,而 FrameB 內的旋轉是 50 度,那麼 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.
-- 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
AbsoluteSize 是一個只供閱取的屬性,它提供的屏幕尺寸是以像素表示 UI 元素的尺寸。這表示元素在結果由其父元素的尺寸而渲染時的實際像素尺寸。此屬性,GuiBase2d.AbsolutePosition 和 GuiBase2d.AbsoluteRotation 是一組用於描述所有元素最終渲染方向的�
舉例:在 1920 由 1080 螢幕上,如果 FrameA 存在於 FrameB 中,且兩個都有 .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.
-- 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
設為真,本 GuiBase2d 和其子代將適用本 LocalizationService:GetTableEntries() 的輸入。 GuiBase2d.AutoLocalize 啟用的輸入將在雲桌表載入後自動重新翻譯,如有需要。 1>Class.LocalizationService:GetTableCommands1> 啟用的輸入將在本
RootLocalizationTable
一個引用 LocalizationTable 以應用自動本地化到這個 GuiBase2d 和它的後代。
Class.GuiBase2d.AutoLocalize 屬性必須在此對象和其父輩設置為真,才能啟用自動本地化。您可以將此設置為對應 RootLocalizationTable
如果沒有可用的翻譯在參考桌中,它會尋找該桌中的翻譯,如果它是一個本地化桌,等等。
也參閱 LocalizationService:GetTableEntries() ,說明如何使用 GuiBase2d.RootLocalizationTable 自動化本在地化。
方法
活動
SelectionChanged
這個事件會在連接的 GuiBase2d 的任何子孫中發生選擇變更時發生。 當選擇高亮移動到 GuiObject 時,事件泡泡從該 GuiObject 傳到所有的祖先,告知他們選擇已變更/已輸入/已退出到他們的子孫樹中的 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.
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)