BasePlayerGui

顯示已棄用項目

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

無法建立

BasePlayerGui 是一個抽象類別,所有的 GUI 繪圖存儲類別都從其中繼承。

屬性

方法

GetGuiObjectsAtPosition

Instances

取得屏幕位置並返回一個列表,包含所有 GuiObject 正在佔用該屏幕位置的實例,排序在屏幕上從上到下的第一和最後索引,分別為第一和最後索引。

主要使用案例是將玩家的滑鼠或觸摸輸入下的 GUI 對象用於執行如允許選擇或標示等操作。這些效果已經可以使用 GuiObject.MouseEnterGuiObject.MouseLeave 來實現,但這需要開發人員隨時跟蹤這些事件,即使他們只需要在特定情況下使用此功能。

因為 BasePlayerGui 子類繼承此功能,因此可以由像 PlayerGuiStarterGui 文件夾等類別對象發射。

參數

應用 GuiInset 後,畫面上的 x 位置相對於左上角。

預設值:""

應用 GuiInset 後,畫面上與左上角相對的 y 位置。

預設值:""

返回

Instances

一個包含給定畫面空間的 GuiObject 實例表。

範例程式碼

All GUIs returned by BasePlayerGui:GetGuiObjectsAtPosition() are 'cloned' by the highlightAsFrame() local function, which creates a Frame GUI positioned on top of the specified GUI that is semi-transparent and the same GuiBase2d.AbsoluteSize and GuiBase2d.AbsolutePosition.

These highlights are added to the HighlightsContainer ScreenGui in the Highlight folder of the player's PlayerGui folder. Both are created by the code sample. All highlight GUIs are Instance:Destroy()ed every time highlightGui() executes.

Note that HighlightContainer's ScreenGui.DisplayOrder is 99999, a large number, so that it is unlikely any other GUI will render on top of the highlight GUIs.

Selecting GUIs at a Position

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Create a Folder and ScreenGui to contain the highlight Frames
local highlights = Instance.new("Folder")
highlights.Name = "Highlights"
highlights.Parent = playerGui
local highlightsContainer = Instance.new("ScreenGui")
highlightsContainer.Name = "Container"
highlightsContainer.Parent = highlights
highlightsContainer.DisplayOrder = 99999
-- Creates a semi-transparent yellow Frame on top of the gui with the same AbsoluteSize and AbsolutePosition
local function highlightAsFrame(gui)
local highlight = Instance.new("Frame")
highlight.Name = "Highlight"
highlight.Parent = highlightsContainer
highlight.Size = UDim2.new(0, gui.AbsoluteSize.X, 0, gui.AbsoluteSize.Y)
highlight.Position = UDim2.new(0, gui.AbsolutePosition.X, 0, gui.AbsolutePosition.Y)
highlight.BackgroundColor3 = Color3.fromRGB(255, 255, 10) -- Yellow
highlight.BackgroundTransparency = 0.75
highlight.BorderSizePixel = 0
highlight.LayoutOrder = gui.LayoutOrder - 1
end
-- Use GetGuiObjectsAtPosition to get and highlight all GuiObjects at the input's position
local function highlightGui(input, _gameProcessed)
local pos = input.Position
local guisAtPosition = playerGui:GetGuiObjectsAtPosition(pos.X, pos.Y)
highlightsContainer:ClearAllChildren()
for _, gui in ipairs(guisAtPosition) do
if gui:IsA("GuiObject") then
highlightAsFrame(gui)
end
end
end
-- Fire highlightGui on InputBegan if input is of type MouseButton1 of Touch
local function InputBegan(input, gameProcessed)
local inputType = input.UserInputType
local touch = Enum.UserInputType.Touch
local mouse1 = Enum.UserInputType.MouseButton1
if inputType == touch or inputType == mouse1 then
highlightGui(input, gameProcessed)
end
end
UserInputService.InputBegan:Connect(InputBegan)

活動