BasePlayerGui

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음

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)

이벤트