GuiObject

사용되지 않는 항목 표시

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

만들 수 없음
찾아볼 수 없음

GuiObject는 2D 사용자 인터페이스 개체에 대한 추상 클래스(BasePart와 비슷함)입니다.그래픽 사용자 인터페이스(GUI) 개체의 표시와 관련된 모든 속성을 정의합니다(예: SizePosition ).또한 AbsolutePosition , AbsoluteSizeAbsoluteRotation와 같은 유용한 읽기 전용 속성이 있습니다.

GUI 개체의 레이아웃을 특별한 방식으로 조작하려면 목록/유연성 또는 그리드와 같은 레이아웃 구조를 사용하고, 모양 수정자를 통해 핵심 속성을 넘어서 스타일링할 수 있습니다.

및 를 사용하여 모든 GUI 개체에서 마우스 버튼 이벤트를 감지할 수는 있지만, 클릭/누르기와 같은 편리한 전용 이벤트는 및 만 있습니다.

요약

속성

속성GuiBase2d에서 상속되었습니다

메서드

이벤트

이벤트GuiBase2d에서 상속되었습니다

속성

Active

병렬 읽기

이 속성은 입력을 와 같은 클래스의 기본 모델로 3D 공간에 싱크할지 여부를 결정합니다.

For GuiButton 개체(ImageButtonTextButton ), 이 속성은 발사가 Activated 여전히 작동하는지 여부를 결정합니다(AutoButtonColor 역시 마찬가지로 작동합니다).이벤트 InputBegan , InputChangedInputEnded 는 이 속성의 값이 무엇이든 정상적으로 작동합니다.

코드 샘플

TextButton Active Debounce

-- Place this LocalScript within a TextButton (or ImageButton)
local textButton = script.Parent
textButton.Text = "Click me"
textButton.Active = true
local function onActivated()
-- This acts like a debounce
textButton.Active = false
-- Count backwards from 5
for i = 5, 1, -1 do
textButton.Text = "Time: " .. i
task.wait(1)
end
textButton.Text = "Click me"
textButton.Active = true
end
textButton.Activated:Connect(onActivated)

AnchorPoint

병렬 읽기

이 속성은 상대적인 크기에 따른 GuiObject 의 원점을 결정합니다.원점은 요소가 위치하는 곳(통해 GuiObject.Position )과 렌더링된 요소가 확장되는 곳(통해 GuiObject.Size )을 결정합니다.

여기 에서 설명된 그림과 세부 정보를 참조하십시오.

코드 샘플

AnchorPoint Demo

local guiObject = script.Parent
while true do
-- Top-left
guiObject.AnchorPoint = Vector2.new(0, 0)
guiObject.Position = UDim2.new(0, 0, 0, 0)
task.wait(1)
-- Top
guiObject.AnchorPoint = Vector2.new(0.5, 0)
guiObject.Position = UDim2.new(0.5, 0, 0, 0)
task.wait(1)
-- Top-right
guiObject.AnchorPoint = Vector2.new(1, 0)
guiObject.Position = UDim2.new(1, 0, 0, 0)
task.wait(1)
-- Left
guiObject.AnchorPoint = Vector2.new(0, 0.5)
guiObject.Position = UDim2.new(0, 0, 0.5, 0)
task.wait(1)
-- Dead center
guiObject.AnchorPoint = Vector2.new(0.5, 0.5)
guiObject.Position = UDim2.new(0.5, 0, 0.5, 0)
task.wait(1)
-- Right
guiObject.AnchorPoint = Vector2.new(1, 0.5)
guiObject.Position = UDim2.new(1, 0, 0.5, 0)
task.wait(1)
-- Bottom-left
guiObject.AnchorPoint = Vector2.new(0, 1)
guiObject.Position = UDim2.new(0, 0, 1, 0)
task.wait(1)
-- Bottom
guiObject.AnchorPoint = Vector2.new(0.5, 1)
guiObject.Position = UDim2.new(0.5, 0, 1, 0)
task.wait(1)
-- Bottom-right
guiObject.AnchorPoint = Vector2.new(1, 1)
guiObject.Position = UDim2.new(1, 0, 1, 0)
task.wait(1)
end

AutomaticSize

병렬 읽기

이 속성은 하위 개체의 크기에 따라 부모 UI 개체의 크기를 자동으로 조정하는 데 사용됩니다.이 속성을 사용하여 편집 또는 런타임에 UI 개체에 텍스트 및 기타 콘텐츠를 동적으로 추가할 수 있으며, 크기가 해당 콘텐츠에 맞게 조정됩니다.

When 가 값으로 설정되면, 이 UI 개체는 자식 콘텐츠에 따라 크기를 조정할 수 있습니다.

이 속성을 사용하고 작동하는 방법에 대한 자세한 정보는 여기를 참조하십시오.

코드 샘플

LocalScript in a ScreenGui

-- Array of text labels/fonts/sizes to output
local labelArray = {
{ text = "Lorem", font = Enum.Font.Creepster, size = 50 },
{ text = "ipsum", font = Enum.Font.IndieFlower, size = 35 },
{ text = "dolor", font = Enum.Font.Antique, size = 55 },
{ text = "sit", font = Enum.Font.SpecialElite, size = 65 },
{ text = "amet", font = Enum.Font.FredokaOne, size = 40 },
}
-- Create an automatically-sized parent frame
local parentFrame = Instance.new("Frame")
parentFrame.AutomaticSize = Enum.AutomaticSize.XY
parentFrame.BackgroundColor3 = Color3.fromRGB(90, 90, 90)
parentFrame.Size = UDim2.fromOffset(25, 100)
parentFrame.Position = UDim2.fromScale(0.1, 0.1)
parentFrame.Parent = script.Parent
-- Add a list layout
local listLayout = Instance.new("UIListLayout")
listLayout.Padding = UDim.new(0, 5)
listLayout.Parent = parentFrame
-- Set rounded corners and padding for visual aesthetics
local roundedCornerParent = Instance.new("UICorner")
roundedCornerParent.Parent = parentFrame
local uiPaddingParent = Instance.new("UIPadding")
uiPaddingParent.PaddingTop = UDim.new(0, 5)
uiPaddingParent.PaddingLeft = UDim.new(0, 5)
uiPaddingParent.PaddingRight = UDim.new(0, 5)
uiPaddingParent.PaddingBottom = UDim.new(0, 5)
uiPaddingParent.Parent = parentFrame
for i = 1, #labelArray do
-- Create an automatically-sized text label from array
local childLabel = Instance.new("TextLabel")
childLabel.AutomaticSize = Enum.AutomaticSize.XY
childLabel.Size = UDim2.fromOffset(75, 15)
childLabel.Text = labelArray[i]["text"]
childLabel.Font = labelArray[i]["font"]
childLabel.TextSize = labelArray[i]["size"]
childLabel.TextColor3 = Color3.new(1, 1, 1)
childLabel.Parent = parentFrame
-- Visual aesthetics
local roundedCorner = Instance.new("UICorner")
roundedCorner.Parent = childLabel
local uiPadding = Instance.new("UIPadding")
uiPadding.PaddingTop = UDim.new(0, 5)
uiPadding.PaddingLeft = UDim.new(0, 5)
uiPadding.PaddingRight = UDim.new(0, 5)
uiPadding.PaddingBottom = UDim.new(0, 5)
uiPadding.Parent = childLabel
task.wait(2)
end

BackgroundColor3

병렬 읽기

이 속성은 배경색(채우기 색)의 색상을 결정합니다 GuiObject .요소에 텍스트가 포함되어 있는 경우, TextBox, TextButton, 또는 TextLabel와 같이, 배경의 색이 텍스트의 색과 대조되는지 확인하십시오.

배경의 시각적 속성을 결정하는 또 다른 속성은 GuiObject.BackgroundTransparency입니다; 이를 1로 설정하면 배경이나 테두리가 렌더링되지 않습니다.

또한 참조하십시오 BorderColor3 .

코드 샘플

Rainbow Frame

-- Put this code in a LocalScript in a Frame
local frame = script.Parent
while true do
for hue = 0, 255, 4 do
-- HSV = hue, saturation, value
-- If we loop from 0 to 1 repeatedly, we get a rainbow!
frame.BorderColor3 = Color3.fromHSV(hue / 256, 1, 1)
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, 0.5, 0.8)
task.wait()
end
end

BackgroundTransparency

병렬 읽기

이 속성은 배경과 경계의 투명도를 결정합니다 GuiObject.그러나 GUI가 TextBox , TextButton 또는 TextLabel인 경우 텍스트 투명도를 결정하지 않으며, 텍스트 투명도는 TextBox.TextTransparency , TextButton.TextTransparencyTextLabel.TextTransparency 각각 결정됩니다.

이 속성이 1로 설정되면 배경이나 테두리가 렌더링되지 않으며 GUI 배경이 완전히 투명해집니다.

BorderColor3

병렬 읽기

GuiObject 사각형 경계의 색상을 결정합니다(또한 스트로크 색상으로 알려짐).이는 개체의 GuiObject.BackgroundColor3 와 별도입니다.속성이 로 설정되어 있으면 개체의 경계를 볼 수 없습니다.

UIStroke 구성 요소는 더 고급한 경계 효과를 허용합니다.

코드 샘플

Button Highlight

-- Put me inside some GuiObject, preferrably an ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Yellow
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Black
end
-- Connect events
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Our default state is "not hovered"
onLeave()

BorderMode

병렬 읽기

이 속성은 같은 이름의 열거형을 사용하여 차원과 관련하여 GuiObject 경계가 배치되는 방식을 결정합니다, Enum.BorderMode .

이 속성을 재정의할 수 있고 더 진보된 경계 효과를 허용하는 UIStroke를 참고하십시오.

BorderSizePixel

병렬 읽기

이 속성은 픽셀당 GuiObject 경계 렌더링의 너비를 결정합니다. 이를 0으로 설정하면 경계가 완전히 비활성화됩니다.

이 속성을 재정의할 수 있고 더 진보된 경계 효과를 허용하는 UIStroke를 참고하십시오.

코드 샘플

Button Highlight

-- Put me inside some GuiObject, preferrably an ImageButton/TextButton
local button = script.Parent
local function onEnter()
button.BorderSizePixel = 2
button.BorderColor3 = Color3.new(1, 1, 0) -- Yellow
end
local function onLeave()
button.BorderSizePixel = 1
button.BorderColor3 = Color3.new(0, 0, 0) -- Black
end
-- Connect events
button.MouseEnter:Connect(onEnter)
button.MouseLeave:Connect(onLeave)
-- Our default state is "not hovered"
onLeave()

ClipsDescendants

병렬 읽기

이 속성은 GuiObject 가 범위를 벗어나 표시되는 것을 방지하기 위해 하위 GUI 요소의 일부를 잘라야 하는지 여부를 결정합니다. 이 속성은 사각형의 경계 밖으로 렌더링되는 것을 방지하기 위해 사용됩니다.

이 속성에서 Rotation 가 지원되지 않는다는 점에 유의하십시오.이 또는 어떤 조상 GUI에 0보다 큰 이 있으면 이 속성이 무시되고 후손 GUI 요소는 이 속성의 값과 무관하게 렌더링됩니다.

읽기 전용
복제되지 않음
병렬 읽기

플레이어의 손가락이 에 탭되고 길게 누르면 의 가 설정됩니다.마찬가지로, 플레이어의 손가락이 에서 해제되면 의 가 설정되고, 가 꺼지면 의 가 설정됩니다.

Interactable

병렬 읽기

GuiButton 와 상호작용할 수 있는지 또는 GuiStateGuiObject 가 변경되는지 여부를 결정합니다.

에서 GuiButton :

에서 GuiObject :

  • 설정이 에 설정되어 있을 때, 는 항상 로 설정됩니다.
  • 설정이 에 설정되어 있을 때, 는 다시 정상적으로 동작합니다.

LayoutOrder

병렬 읽기

이 속성은 (예: 또는 )를 사용하여 정렬 순서를 제어하며 에 설정됩니다.개체에 형제 UI 레이아웃 구조가 없으면 기능이 없습니다.

GuiObjects 는 낮은 값이 더 높은 값보다 우선하는 순서로 정렬됩니다.동일한 값을 가진 개체는 추가된 순서로 되돌아갑니다.

미래에 두 개의 기존 요소 사이에 요소를 추가해야 하는지 확신할 수 없는 경우, 100( 0 , 100 , 200 등)의 배수를 사용하는 것이 좋습니다.이렇게 하면 다른 요소 사이에 주문된 요소에 사용할 수 있는 큰 레이아웃 순서 값의 간격이 보장됩니다.

또한 참조하십시오 ZIndex 는 순서를 정렬하는 대신 개체의 렌더링 순서를 결정합니다.

NextSelectionDown

병렬 읽기

이 속성은 사용자가 게임패드 선택기를 아래로 이동할 때 선택된 속성을 설정합니다.이 속성이 비어 있으면 게임패드를 아래로 이동해도 선택한 GUI가 변경되지 않습니다.

게임패드 선택기를 아래로 이동하면 GUI가 아닌 경우 이 개체에 설정됩니다.이 속성은 Selectable이 아니더라도 GUI 요소로 설정할 수 있으므로 GUI의 선택 가능한 속성 값이 예상 행동과 일치하는지 확인해야 합니다.

또한 참조하십시오 NextSelectionUp , NextSelectionLeft , 및 NextSelectionRight .

코드 샘플

Creating a Gamepad Selection Grid

-- Setup the Gamepad selection grid using the code below
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Left edge
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Right edge
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Above
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Below
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Test the Gamepad selection grid using the code below
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

NextSelectionLeft

병렬 읽기

이 속성은 사용자가 게임패드 선택기를 왼쪽으로 이동할 때 선택된 을 설정합니다.이 속성이 비어 있으면 게임패드를 왼쪽으로 이동해도 선택한 GUI가 변경되지 않습니다.

게임패드 선택기를 왼쪽으로 이동하면 GUI가 아닌 경우 에 이 개체로 설정됩니다.이 속성은 Selectable이 아니더라도 GUI 요소로 설정할 수 있으므로 GUI의 선택 가능한 속성 값이 예상 행동과 일치하는지 확인해야 합니다.

또한 참조하십시오 NextSelectionUp , NextSelectionDown , 및 NextSelectionRight .

코드 샘플

Creating a Gamepad Selection Grid

-- Setup the Gamepad selection grid using the code below
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Left edge
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Right edge
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Above
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Below
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Test the Gamepad selection grid using the code below
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

NextSelectionRight

병렬 읽기

이 속성은 사용자가 게임패드 선택기를 오른쪽으로 이동할 때 선택된 을 설정합니다.이 속성이 비어 있으면 게임패드를 오른쪽으로 이동해도 선택한 GUI가 변경되지 않습니다.

게임패드 선택기를 오른쪽으로 이동하면 GUI가 아닌 경우 에 이 개체로 설정됩니다.이 속성은 Selectable이 아니더라도 GUI 요소로 설정할 수 있으므로 GUI의 선택 가능한 속성 값이 예상 행동과 일치하는지 확인해야 합니다.

또한 참조하십시오 NextSelectionUp , NextSelectionDown , 및 NextSelectionLeft .

코드 샘플

Creating a Gamepad Selection Grid

-- Setup the Gamepad selection grid using the code below
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Left edge
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Right edge
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Above
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Below
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Test the Gamepad selection grid using the code below
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

NextSelectionUp

병렬 읽기

이 속성은 사용자가 게임패드 선택기를 위쪽으로 이동할 때 선택된 속성을 설정합니다.이 속성이 비어 있으면 게임패드를 위쪽으로 이동하더라도 선택한 GUI가 변경되지 않습니다.

게임패드 선택기를 위쪽으로 이동하면 GUI가 아닌 경우 에 이 개체로 설정됩니다.이 속성은 Selectable이 아니더라도 GUI 요소로 설정할 수 있으므로 GUI의 선택 가능한 속성 값이 예상 행동과 일치하는지 확인해야 합니다.

또한 참조하십시오 NextSelectionDown , NextSelectionLeft , NextSelectionRight .

코드 샘플

Creating a Gamepad Selection Grid

-- Setup the Gamepad selection grid using the code below
local container = script.Parent:FindFirstChild("Container")
local grid = container:GetChildren()
local rowSize = container:FindFirstChild("UIGridLayout").FillDirectionMaxCells
for _, gui in pairs(grid) do
if gui:IsA("GuiObject") then
local pos = gui.Name
-- Left edge
gui.NextSelectionLeft = container:FindFirstChild(pos - 1)
-- Right edge
gui.NextSelectionRight = container:FindFirstChild(pos + 1)
-- Above
gui.NextSelectionUp = container:FindFirstChild(pos - rowSize)
-- Below
gui.NextSelectionDown = container:FindFirstChild(pos + rowSize)
end
end
-- Test the Gamepad selection grid using the code below
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
GuiService.SelectedObject = container:FindFirstChild("1")
function updateSelection(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
local selectedObject = GuiService.SelectedObject
if not selectedObject then
return
end
if key == Enum.KeyCode.Up then
if not selectedObject.NextSelectionUp then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Down then
if not selectedObject.NextSelectionDown then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Left then
if not selectedObject.NextSelectionLeft then
GuiService.SelectedObject = selectedObject
end
elseif key == Enum.KeyCode.Right then
if not selectedObject.NextSelectionRight then
GuiService.SelectedObject = selectedObject
end
end
end
end
UserInputService.InputBegan:Connect(updateSelection)

Position

병렬 읽기

이 속성은 GuiObject 픽셀과 스칼라 위치를 UDim2를 사용하여 결정합니다. 위치는 개체의 GuiObject.AnchorPoint 주위에 중앙화됩니다.

스칼라 위치는 부모 GUI 요소의 크기에 대해 상대적입니다, 있는 경우.

UDim2 값의 픽셀 부분은 부모 GUI의 크기에 관계없이 동일합니다.값은 픽셀 단위의 개체 위치를 나타냅니다.개체의 실제 픽셀 위치는 GuiBase2d.AbsolutePosition 속성에서 읽을 수 있습니다.

Rotation

병렬 읽기

이 속성은 회전되는 GuiObject의 정도 수를 결정합니다.회전은 개체의 중앙 에 대한 상대적인 것으로, 아님 , 즉 회전 지점을 변경할 수 없습니다.또한 이 속성은 ClipsDescendants 와 호환되지 않습니다.

Selectable

병렬 읽기

이 속성은 게임패드를 사용하여 GUI를 탐색할 때 GuiObject가 선택될 수 있는지 여부를 결정합니다.

이 속성이 true 인 경우 GUI를 선택할 수 있습니다. GUI를 선택하면 GuiService.SelectedObject 속성도 해당 개체로 설정됩니다.

이것이 false, GUI를 선택할 수 없습니다.그러나 GUI를 선택할 때 이를 false로 설정하면 선택 해제하거나 GuiService.SelectedObject 속성의 값을 변경하지 않습니다.

GuiObject.SelectionGainedGuiObject.SelectionLost 를 추가하면 요소에 대해 발사되지 않습니다. GuiObject를 선택 취소하려면 GuiService.SelectedObject 속성을 변경해야 합니다.

이 속성은 GUI가 이러한 속성(예: GuiObject.NextSelectionUp, GuiObject.NextSelectionDown, NextSelectionRight, 또는 NextSelectionLeft )을 통해 여러 GUI에 연결되어 있는 경우 유용합니다.게임패드가 GUI를 선택할 수 없도록 모든 속성을 변경하는 대신, 선택 가능 속성을 비활성화하여 일시적으로 선택되지 않도록 방지할 수 있습니다.그런 다음, 게임패드 선택기가 GUI를 선택할 수 있도록 하려면 선택 가능한 속성을 다시 활성화하면 됩니다.

코드 샘플

Limiting TextBox Selection

local GuiService = game:GetService("GuiService")
local textBox = script.Parent
local function gainFocus()
textBox.Selectable = true
GuiService.SelectedObject = textBox
end
local function loseFocus(_enterPressed, _inputObject)
GuiService.SelectedObject = nil
textBox.Selectable = false
end
-- The FocusLost and FocusGained event will fire because the textBox
-- is of type TextBox
textBox.Focused:Connect(gainFocus)
textBox.FocusLost:Connect(loseFocus)

SelectionImageObject

병렬 읽기

이 속성은 게임패드에 사용되는 기본 선택 장식을 재정의합니다.

선택한 SelectionImageObject 가 선택한 GuiObject 에 이미지의 Size 를 겹치게 합니다.최상의 결과를 얻으려면 크기를 조정하여 사용자 지정 SelectionImageObject 을 스케일 UDim2 값을 통해 확장하여 선택한 요소에서 개체가 올바르게 확장되도록 해야 합니다.

변경하는 요소는 해당 요소에만 영향을 미칩니다. 사용자의 GUI 요소 전체에 영향을 주려면 속성을 설정하십시오.

사용자가 선택한 GUI 요소를 결정하거나 설정하려면 GuiService.SelectedObject 속성을 사용할 수 있습니다.플레이어는 게임패드를 사용하여 다른 GUI 요소를 선택하고, NextSelectionUp, NextSelectionDown, NextSelectionLeftNextSelectionRight 이벤트를 트리거합니다.

SelectionOrder

병렬 읽기

더 낮은 선택 순서를 가진 GuiObjects는 게임패드 선택을 시작하거나 조상에서 GuiService:Select()를 호출할 때 더 높은 선택 순서를 가진 GuiObjects보다 먼저 선택됩니다.이 속성은 방향 탐색에 영향을 주지 않습니다.기본값은 0입니다.

Size

병렬 읽기

이 속성은 GuiObject를 사용하여 스칼라 및 픽셀 크기를 결정합니다.Pixel size using a UDim2.

스칼라 크기는 부모 GUI 요소의 크기와 비교됩니다(있는 경우).

UDim2 값의 픽셀 부분은 부모 GUI의 크기에 관계없이 동일합니다.값은 픽셀 단위의 개체 크기를 나타냅니다.개체의 실제 픽셀 크기는 GuiBase2d.AbsoluteSize 속성에서 읽을 수 있습니다.

GuiObject 에 부모가 있는 경우, 각 축의 크기는 부모의 SizeConstraint에도 영향을 받습니다.

코드 샘플

Health Bar

local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Paste script into a LocalScript that is
-- parented to a Frame within a Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- black
-- This function is called when the humanoid's health changes
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Change the size of the inner bar
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Change the color of the health bar
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- black
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- yellow
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- green
end
end
-- This function runs is called the player spawns in
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Pattern: update once now, then any time the health changes
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Connect our spawn listener; call it if already spawned
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end

SizeConstraint

병렬 읽기

이 속성은 Size축이 부모의 크기에 비해 기반으로 사용할 것인 축을 설정하며, GuiObject는 부모의 크기에 비례합니다.

이 속성은 부모 개체의 너비 또는 높이로 확장되는 GUI 개체를 만들고, 효과적으로 개체의 비율을 유지하는 데 유용합니다.

Transparency

숨김
복제되지 않음
병렬 읽기

BackgroundTransparencyTextTransparency 의 혼합 속성.

Visible

병렬 읽기

이 속성은 GuiObject 및 그 하위 요소가 렌더링되는지 여부입니다.

의 개별 구성 요소 렌더링은 투명도 속성( 및 등)을 통해 개별적으로 제어할 수 있습니다.

이 속성이 false 일 때, GuiObjectUIListLayout , UIGridLayoutUITableLayout와 같은 레이아웃 구조에서 무시됩니다.즉, 요소가 레이아웃에서 차지할 공간은 다른 요소가 대신 사용합니다.

코드 샘플

UI Window

local gui = script.Parent
local window = gui:WaitForChild("Window")
local toggleButton = gui:WaitForChild("ToggleWindow")
local closeButton = window:WaitForChild("Close")
local function toggleWindowVisbility()
-- Flip a boolean using the `not` keyword
window.Visible = not window.Visible
end
toggleButton.Activated:Connect(toggleWindowVisbility)
closeButton.Activated:Connect(toggleWindowVisbility)

ZIndex

병렬 읽기

이 속성은 다른 사람들에 비해 GuiObject가 렌더링되는 순서를 결정합니다.

기본적으로, 가장 낮은 값을 가진 사람들이 더 높은 값을 가진 사람들 아래에서 렌더링되는 순서대로 렌더링됩니다. , 또는 의 값을 변경하여 렌더링 순서를 변경할 수 있습니다.

미래에 두 개의 기존 요소 사이에 요소를 추가해야 하는지 확신할 수 없는 경우, 100( 0 , 100 , 200 등)의 배수를 사용하는 것이 좋습니다.이렇게 하면 다른 요소 사이에 중첩된 요소에 사용할 수 있는 렌더링 순서 값의 큰 간격이 보장됩니다.

또한 레이아웃 구조(예: 또는 )와 함께 사용할 때의 정렬 순서를 제어하는 을 참조하십시오.

메서드

TweenPosition

지정된 시간에 지정된 Enum.EasingDirectionEnum.EasingStyle를 사용하여 GUI를 부드럽게 새로운 UDim2 위치로 이동합니다.

이 함수는 십대가 플레이여부를 반환합니다.다른 십대가 GuiObject에서 작동하고 재정의 매개변수가 false인 경우 재생하지 않습니다.

또한 참조하십시오 GuiObject:TweenSize()GuiObject:TweenSizeAndPosition() .

매개 변수

endPosition: UDim2

GUI가 이동해야 할 위치.

기본값: ""
easingDirection: Enum.EasingDirection

GUI를 끝 위치로 쉽게 만드는 방향.

기본값: "Out"
easingStyle: Enum.EasingStyle

GUI를 끝 위치로 쉽게 만드는 스타일.

기본값: "Quad"
time: number

청소년이 완료하는 데 걸리는 시간(초)입니다.

기본값: 1
override: boolean

십대가 진행 중인 십대를 재정의할지 여부.

기본값: false
callback: function

트윈이 완료될 때 실행할 콜백 함수.

기본값: "nil"

반환

십대가 플레이할지 여부.

코드 샘플

Tween a GUI's Position

local START_POSITION = UDim2.new(0, 0, 0, 0)
local GOAL_POSITION = UDim2.new(1, 0, 1, 0)
local guiObject = script.Parent
local function callback(state)
if state == Enum.TweenStatus.Completed then
print("The tween completed uninterrupted")
elseif state == Enum.TweenStatus.Canceled then
print("Another tween cancelled this one")
end
end
-- Initialize the GuiObject position, then start the tween:
guiObject.Position = START_POSITION
local willPlay = guiObject:TweenPosition(
GOAL_POSITION, -- Final position the tween should reach
Enum.EasingDirection.In, -- Direction of the easing
Enum.EasingStyle.Sine, -- Kind of easing to apply
2, -- Duration of the tween in seconds
true, -- Whether in-progress tweens are interrupted
callback -- Function to be callled when on completion/cancelation
)
if willPlay then
print("The tween will play")
else
print("The tween will not play")
end

TweenSize

지정된 시간에 지정된 및 를 사용하여 부드럽게 새로운 에 크기를 조정합니다.

이 함수는 십대가 플레이여부를 반환합니다.일반적으로 이것은 항상 true 를 반환하지만, 다른 십대가 활성화되고 재정의가 false 로 설정되면 false로 반환됩니다.

또한 참조하십시오 GuiObject:TweenSize()GuiObject:TweenSizeAndPosition() .

매개 변수

endSize: UDim2

GUI의 크기를 조정해야 하는 크기입니다.

기본값: ""
easingDirection: Enum.EasingDirection

GUI를 끝 크기로 쉽게 만드는 방향입니다 endSize.

기본값: "Out"
easingStyle: Enum.EasingStyle

GUI를 endSize로 쉽게 만드는 스타일.

기본값: "Quad"
time: number

청소년이 완료하는 데 걸리는 시간(초)입니다.

기본값: 1
override: boolean

십대가 진행 중인 십대를 재정의할지 여부.

기본값: false
callback: function

트윈이 완료될 때 실행할 콜백 함수.

기본값: "nil"

반환

십대가 플레이할지 여부.

코드 샘플

Tween a GuiObject's Size

local guiObject = script.Parent
local function callback(didComplete)
if didComplete then
print("The tween completed successfully")
else
print("The tween was cancelled")
end
end
local willTween = guiObject:TweenSize(
UDim2.new(0.5, 0, 0.5, 0), -- endSize (required)
Enum.EasingDirection.In, -- easingDirection (default Out)
Enum.EasingStyle.Sine, -- easingStyle (default Quad)
2, -- time (default: 1)
true, -- should this tween override ones in-progress? (default: false)
callback -- a function to call when the tween completes (default: nil)
)
if willTween then
print("The GuiObject will tween")
else
print("The GuiObject will not tween")
end

TweenSizeAndPosition

지정된 UDim2Enum.EasingDirectionEnum.EasingStyle 를 사용하여 지정된 시간에 새로운 GUI 크기와 위치로 크기를 조정하고 이동합니다.

이 함수는 십대가 플레이여부를 반환합니다.일반적으로 이것은 항상 true 를 반환하지만, 다른 십대가 활성화되고 재정의가 false 로 설정되면 false로 반환됩니다.

또한 참조하십시오 GuiObject:TweenSize()GuiObject:TweenSizeAndPosition() .

매개 변수

endSize: UDim2

GUI의 크기를 조정해야 하는 크기입니다.

기본값: ""
endPosition: UDim2

GUI가 이동해야 할 위치.

기본값: ""
easingDirection: Enum.EasingDirection

GUI를 끝 크기 endSize 및 끝 위치 endPosition로 쉽게 만드는 방향.

기본값: "Out"
easingStyle: Enum.EasingStyle

GUI를 endSizeendPosition으로 쉽게 만드는 스타일.

기본값: "Quad"
time: number

청소년이 완료하는 데 걸리는 시간(초)입니다.

기본값: 1
override: boolean

십대가 진행 중인 십대를 재정의할지 여부.

기본값: false
callback: function

트윈이 완료될 때 실행할 콜백 함수.

기본값: "nil"

반환

십대가 플레이할지 여부.

코드 샘플

Tween a GUI's Size and Position

local frame = script.Parent.Frame
frame:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0, 0, 0, 0))

이벤트

InputBegan

이 이벤트는 사용자가 인간-컴퓨터 인터페이스 장치(마우스 버튼 다운, 터치 시작, 키보드 버튼 다운 등)를 통해 GuiObject와 상호작용하기 시작할 때 발생합니다.

UserInputService 에는 특정 UI 요소에 제한되지 않는 유사하게 이름이 지정된 이벤트가 있습니다: UserInputService.InputBegan .

이 이벤트는 게임 상태에 관계없이 항상 발생합니다.

또한 참조하십시오 GuiObject.InputEndedGuiObject.InputChanged .

매개 변수

InputObject , 유용한 사용자 입력 쿼리에 대한 데이터를 포함하는 것으로, type of input , state of input , 및 screen coordinates of the input 과 같은 것.


코드 샘플

Tracking the Beginning of Input on a GuiObject

-- In order to use the InputBegan event, you must specify the GuiObject
local gui = script.Parent
-- A sample function providing multiple usage cases for various types of user input
local function inputBegan(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("A key is being pushed down! Key:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("The left mouse button has been pressed down at", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("The right mouse button has been pressed down at", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("A touchscreen input has started at", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("A button is being pressed on a gamepad! Button:", input.KeyCode)
end
end
gui.InputBegan:Connect(inputBegan)

InputChanged

이 이벤트는 사용자가 인간-컴퓨터 인터페이스 장치(마우스 버튼 아래로, 터치 시작, 키보드 버튼 아래로 등)를 통해 상호 작용하는 방식을 변경할 때 발생합니다.

UserInputService 에는 특정 UI 요소에 제한되지 않는 유사하게 이름이 지정된 이벤트가 있습니다: UserInputService.InputChanged .

이 이벤트는 게임 상태에 관계없이 항상 발생합니다.

또한 참조하십시오 GuiObject.InputBeganGuiObject.InputEnded .

매개 변수

InputObject , 유용한 사용자 입력 쿼리에 대한 데이터를 포함하는 것으로, type of input , state of input , 및 screen coordinates of the input 과 같은 것.


코드 샘플

GuiObject InputChanged Demo

local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local function printMovement(input)
print("Position:", input.Position)
print("Movement Delta:", input.Delta)
end
local function inputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("The mouse has been moved!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
print("The mouse wheel has been scrolled!")
print("Wheel Movement:", input.Position.Z)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
print("The left thumbstick has been moved!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
print("The right thumbstick has been moved!")
printMovement(input)
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
print("The pressure being applied to the left trigger has changed!")
print("Pressure:", input.Position.Z)
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
print("The pressure being applied to the right trigger has changed!")
print("Pressure:", input.Position.Z)
end
elseif input.UserInputType == Enum.UserInputType.Touch then
print("The user's finger is moving on the screen!")
printMovement(input)
elseif input.UserInputType == Enum.UserInputType.Gyro then
local _rotInput, rotCFrame = UserInputService:GetDeviceRotation()
local rotX, rotY, rotZ = rotCFrame:toEulerAnglesXYZ()
local rot = Vector3.new(math.deg(rotX), math.deg(rotY), math.deg(rotZ))
print("The rotation of the user's mobile device has been changed!")
print("Position", rotCFrame.p)
print("Rotation:", rot)
elseif input.UserInputType == Enum.UserInputType.Accelerometer then
print("The acceleration of the user's mobile device has been changed!")
printMovement(input)
end
end
gui.InputChanged:Connect(inputChanged)

InputEnded

입력 종료 이벤트는 사용자가 인간-컴퓨터 인터페이스 장치(마우스 버튼 아래로, 터치 시작, 키보드 버튼 아래로 등)를 통해 상호 작용을 중단할 때 발생합니다.

UserInputService 에는 특정 UI 요소에 제한되지 않는 유사하게 이름이 지정된 이벤트가 있습니다: UserInputService.InputEnded .

이 이벤트는 게임 상태에 관계없이 항상 발생합니다.

또한 참조하십시오 GuiObject.InputBeganGuiObject.InputChanged .

매개 변수

InputObject , 유용한 사용자 입력 쿼리에 대한 데이터를 포함하는 것으로, Enum.UserInputType , Enum.UserInputState , 및 InputObject.Position 과 같은 것.


코드 샘플

Tracking the End of Input on a GuiObject

-- In order to use the InputChanged event, you must specify a GuiObject
local gui = script.Parent
-- A sample function providing multiple usage cases for various types of user input
local function inputEnded(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("A key has been released! Key:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("The left mouse button has been released at", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("The right mouse button has been released at", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("A touchscreen input has been released at", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("A button has been released on a gamepad! Button:", input.KeyCode)
end
end
gui.InputEnded:Connect(inputEnded)

MouseEnter

마우스 입력 이벤트는 사용자가 마우스를 GuiObject 요소로 이동할 때 발생합니다.

이 이벤트에서 전달된 xy 인수를 사용하여 사용자의 마우스가 GUI에 들어갈 때 위치를 결정하는 방법으로 오용하지 마십시오.마우스가 같은 가장자리를 통해 GUI에 들어갈 때에도 이러한 좌표는 변할 수 있습니다. 특히 마우스가 요소에 신속하게 들어갈 때 그렇습니다.이는 좌표가 마우스가 GUI에 들어갈 정확한 순간이 아닌 이벤트가 발생할 때 마우스 위치를 나타내기 때문입니다.

이 이벤트는 GUI 요소가 다른 요소 아래에 렌더링될 때에도 발생합니다.

사용자의 마우스가 GUI 요소를 떠났을 때 추적하려는 경우 GuiObject.MouseLeave 이벤트를 사용할 수 있습니다.

또한 참조하세요

매개 변수

마우스의 X 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.

마우스의 Y 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.


코드 샘플

Printing where a Mouse Enters a GuiObject

local guiObject = script.Parent
guiObject.MouseEnter:Connect(function(x, y)
print("The user's mouse cursor has entered the GuiObject at position", x, ",", y)
end)

MouseLeave

마우스 떠나 이벤트는 사용자가 마우스를 GuiObject 요소에서 이동할 때 발생합니다.

이 이벤트에서 전달된 xy 인수를 사용하여 사용자의 마우스가 GUI를 떠날 때 위치를 결정하는 방법으로 오용하지 마십시오.마우스가 같은 가장자리를 통해 GUI를 떠날 때에도 이러한 좌표는 변경될 수 있습니다. 특히 마우스가 요소를 신속하게 떠날 때입니다.이는 좌표가 마우스가 GUI를 떠난 정확한 순간이 아닌 이벤트가 발생할 때 마우스 위치를 나타내기 때문입니다.

이 이벤트는 GUI 요소가 다른 요소 아래에 렌더링될 때에도 발생합니다.

또한 참조하세요

매개 변수

마우스의 X 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.

마우스의 Y 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.


MouseMoved

사용자가 내부에 있는 GuiObject 요소에서 마우스를 이동할 때마다 발생합니다.사용자의 마우스가 GUI 요소 위에 있는지 여부에 관계없이 발생하는 Mouse.Move와 유사합니다.

참고, 이 이벤트는 마우스 위치가 업데이트될 때 발생하므로 이동하는 동안 반복해서 발생합니다.

xy 인수는 픽셀로 사용자의 마우스 업데이트된 화면 좌표를 나타냅니다.이것은 전역 변수에서 추적되는 경우 마우스의 GUI, 화면 및 델타 위치를 결정하는 데 유용할 수 있습니다.

아래 코드는 GUI 요소에 대한 사용자 마우스의 오프셋을 결정하는 방법을 보여줍니다: Vector2


local Players = game:GetService("Players")
local CustomScrollingFrame = script.Parent
local SubFrame = CustomScrollingFrame:FindFirstChild("SubFrame")
local mouse = Players.LocalPlayer:GetMouse()
local function getPosition(X, Y)
local gui_X = CustomScrollingFrame.AbsolutePosition.X
local gui_Y = CustomScrollingFrame.AbsolutePosition.Y
local pos = Vector2.new(math.abs(X - gui_X), math.abs(Y - gui_Y - 36))
print(pos)
end
CustomScrollingFrame.MouseMoved:Connect(getPosition)

사용자의 마우스가 GUI 요소에 들어가거나 나갈 때 정확히 이벤트가 발생하지 않을 수 있습니다. Note that this event may not fire exactly when the user's mouse enters or exits a GUI element.따라서 xy 인수는 GUI 가장자리의 좌표와 완벽하게 일치하지 않을 수 있습니다.

또한 참조하세요

매개 변수

마우스의 X 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.

마우스의 Y 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.


MouseWheelBackward

바퀴 뒤로 이벤트는 사용자가 마우스 바퀴를 뒤로 스크롤할 때 마우스가 요소 GuiObject 위에 있을 때 발생합니다.사용자의 마우스가 GUI 요소 위에 있는지 여부에 관계없이 발생하는 Mouse.WheelBackward와 유사합니다.

이 이벤트는 단순히 바퀴의 후방 이동 표시기로만 발생합니다.즉, xy 마우스 좌표 인수가 이 이벤트의 결과로 변경되지 않습니다.이 좌표는 마우스가 이동할 때만 변경되며, GuiObject.MouseMoved 이벤트를 통해 추적할 수 있습니다.

또한 참조하세요

매개 변수

마우스의 X 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.

마우스의 Y 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.


MouseWheelForward

바퀴 앞 이벤트는 마우스가 요소 GuiObject 위에 있을 때 사용자가 마우스 바퀴를 앞으로 스크롤할 때 발생합니다.사용자의 마우스가 GUI 요소 위에 있는지 여부에 관계없이 발생하는 Mouse.WheelForward와 유사합니다.

이 이벤트는 단순히 바퀴의 앞쪽 이동을 나타내는 표시기로만 발생합니다.즉, XY 마우스 좌표 인수가 이 이벤트의 결과로 변경되지 않습니다.이 좌표는 마우스가 이동할 때만 변경되며, GuiObject.MouseMoved 이벤트를 통해 추적할 수 있습니다.

또한 참조하세요

매개 변수

마우스의 X 화면 좌표는 화면 왼쪽 상단 모서리와 관련하여 픽셀로 표시됩니다.

사용자의 마우스 좌표 Y .


SelectionGained

이 이벤트는 게임패드 선택기가 GuiObject에 초점을 맞추기 시작할 때 발생합니다.

게임패드에서 GUI 요소에 집중하지 않고 확인하려면 GuiObject.SelectionLost 이벤트를 사용할 수 있습니다.

GUI가 선택 포커스를 얻으면 SelectedObject 속성의 값도 선택 포커스를 얻습니다.어떤 GUI가 선택을 받았는지 확인하려면 이 속성의 값을 확인하십시오.


코드 샘플

Handling GUI Selection Gained

local guiObject = script.Parent
local function selectionGained()
print("The user has selected this button with a gamepad.")
end
guiObject.SelectionGained:Connect(selectionGained)

SelectionLost

이 이벤트는 게임패드 선택기가 GuiObject에 초점을 맞추지 않을 때 발생합니다.

게임패드에서 확인하려면 GUI 요소에 초점을 맞추기 시작하는 이벤트 GuiObject.SelectionGained)를 사용할 수 있습니다.

GUI가 선택 포커스를 잃으면 속성 값이 선택 포커스를 얻은 GUI 요소로 변경되거나 선택 포커스를 얻은 GUI 요소로 변경됩니다.어떤 GUI가 선택을 받았는지 또는 GUI가 선택되지 않은 경우 이 속성의 값을 확인하십시오.


코드 샘플

Handling GUI Selection Lost

local guiObject = script.Parent
local function selectionLost()
print("The user no longer has this selected with their gamepad.")
end
guiObject.SelectionLost:Connect(selectionLost)

TouchLongPress

이 이벤트는 터치 활성화 장치를 사용하여 UI 요소에 손가락을 대고 잠시 후에 발생합니다. This event fires after a brief moment when the player holds their finger on the UI element using a touch-enabled device.그것은 제스처와 관련된 손가락의 상대적인 화면 위치를 설명하는 Vector2 테이블로 발사됩니다.또한 여러 번 발사합니다: Enum.UserInputState.Begin 짧은 지연 후, Enum.UserInputState.Change 플레이어가 제스처 중에 손가락을 움직이면, 그리고 마지막으로 Enum.UserInputState.End .지연은 플랫폼에 따라 다르며, Studio에서는 1초보다 조금 더 깁니다.

이 이벤트는 한 손가락만 필요하기 때문에, 이 이벤트는 에뮬레이터와 마우스를 사용하여 Studio에서 시뮬레이션할 수 있습니다.

매개 변수

touchPositions: Array

제스처와 관련된 손가락의 상대적인 위치를 설명하는 배열.

제스처의 상태를 설명하는 A Enum.UserInputState :

  • 제스처가 시작될 때 한 번 화재 시작(짧은 지연 후)
  • 플레이어가 핀을 누르는 동안 손가락을 움직이면 화염을 변경
  • 손가락을 놓을 때 제스처가 끝날 때 한 번 화재를 종료합니다.

코드 샘플

Move UI Element with TouchLongPress

local frame = script.Parent
frame.Active = true
local dragging = false
local basePosition
local startTouchPosition
local borderColor3
local backgroundColor3
local function onTouchLongPress(touchPositions, state)
if state == Enum.UserInputState.Begin and not dragging then
-- Start a drag
dragging = true
basePosition = frame.Position
startTouchPosition = touchPositions[1]
-- Color the frame to indicate the drag is happening
borderColor3 = frame.BorderColor3
backgroundColor3 = frame.BackgroundColor3
frame.BorderColor3 = Color3.new(1, 1, 1) -- White
frame.BackgroundColor3 = Color3.new(0, 0, 1) -- Blue
elseif state == Enum.UserInputState.Change then
local touchPosition = touchPositions[1]
local deltaPosition =
UDim2.new(0, touchPosition.X - startTouchPosition.X, 0, touchPosition.Y - startTouchPosition.Y)
frame.Position = basePosition + deltaPosition
elseif state == Enum.UserInputState.End and dragging then
-- Stop the drag
dragging = false
frame.BorderColor3 = borderColor3
frame.BackgroundColor3 = backgroundColor3
end
end
frame.TouchLongPress:Connect(onTouchLongPress)

TouchPan

이 이벤트는 터치 활성화 기기사용하여 UI 요소에 손가락을 이동할 때 발생합니다.그것은 짧은 시간 전에 발사되며, 가 발사되기 전에는 발사하지 않습니다.이 이벤트는 플레이어가 화면에서 UI 요소의 위치를 조작할 수 있게 하는 데 유용합니다.

이 이벤트는 제스처와 관련된 손가락의 상대 화면 위치를 설명하는 Vector2 테이블과 함께 발생합니다.또한 여러 번 발사합니다: Enum.UserInputState.Begin 짧은 지연 후, Enum.UserInputState.Change 플레이어가 제스처 중에 손가락을 움직일 때, 그리고 마지막으로 Enum.UserInputState.End .

이 이벤트는 에뮬레이터와 마우스를 사용하여 Studio에서 시뮬레이션할 수 없으며, 발사하려면 실제 터치 활성화 장치가 있어야 합니다.

매개 변수

touchPositions: Array

Luau 배열의 Vector2 개체, 각각 제스처와 관련된 모든 손가락의 위치를 나타냅니다.

totalTranslation: Vector2

팬 제스처가 시작 지점에서 얼마나 멀리 갔는지 나타냅니다.

velocity: Vector2

각 차원에서 제스처가 얼마나 빨리 수행되는지 나타냅니다.

제스처의 Enum.UserInputState를 나타냅니다.


코드 샘플

Panning UI Element

local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local basePosition
local function onTouchPan(_touchPositions, totalTranslation, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
basePosition = innerFrame.Position
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
innerFrame.Position = basePosition + UDim2.new(0, totalTranslation.X, 0, totalTranslation.Y)
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPan:Connect(onTouchPan)

TouchPinch

이 이벤트는 터치 활성화 장치를 사용하여 UI 요소에 핀치 또는 당기기 제스처를 수행하는 플레이어가 두 손가락을 사용할 때 발생합니다.A 핀치 는 두 개 이상의 손가락이 가까이 이동하면 발생하고, A 당기기 는 그들이 분리되면 발생합니다.이 이벤트는 GuiObject.TouchPan와 함께 발생합니다.이 이벤트는 플레이어가 화면에서 UI 요소의 크기(규모)를 조작할 수 있도록 하고, 대부분 확대 기능으로 사용됩니다.

이 이벤트는 제스처와 관련된 손가락의 상대 화면 위치를 설명하는 Vector2 테이블과 함께 발생합니다.또한 여러 번 발사합니다: Enum.UserInputState.Begin 짧은 지연 후에, Enum.UserInputState.Change 플레이어가 제스처 중에 손가락을 움직일 때, 그리고 마지막으로 Enum.UserInputState.End .규모는 곱하여 사용되어야 한다는 점에 유의해야 합니다 .

이 이벤트는 최소 2개의 손가락이 필요하기 때문에, 에뮬레이터와 마우스를 사용하여 Studio에서 시뮬레이션하는 것은 불가능합니다; 실제로 터치가 가능한 기기있어야 합니다.

매개 변수

touchPositions: Array

Luau 배열의 Vector2 개체, 각각 핀치 제스처에 참여하는 모든 손가락의 위치를 나타냅니다.

scale: number

핀치 제스처의 시작부터 차이를 나타내는 부동 소수점입니다.

velocity: number

핀치 제스처가 얼마나 빨리 발생하는지를 나타내는 부동 소수점입니다.

제스처의 Enum.UserInputState를 나타냅니다.


코드 샘플

Pinch/Pull Scaling

local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local uiScale = Instance.new("UIScale")
uiScale.Parent = innerFrame
local baseScale
local function onTouchPinch(_touchPositions, scale, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
baseScale = uiScale.Scale
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
uiScale.Scale = baseScale * scale -- Notice the multiplication here
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchPinch:Connect(onTouchPinch)

TouchRotate

이 이벤트는 터치 활성화 장치를 사용하여 UI 요소에 핀치 또는 당기기 제스처를 수행하는 플레이어가 두 손가락을 사용할 때 발생합니다.회전은 두 손가락 사이의 선 각도가 변경될 때 발생합니다.이 이벤트는 GuiObject.TouchPan와 함께 발생합니다.이 이벤트는 플레이어가 화면에서 UI 요소의 회전을 조작할 수 있도록 하는 데 유용합니다.

이 이벤트는 제스처와 관련된 손가락의 상대 화면 위치를 설명하는 Vector2 테이블과 함께 발생합니다.또한 여러 번 발사합니다: Enum.UserInputState.Begin 짧은 지연 후에, Enum.UserInputState.Change 플레이어가 제스처 중에 손가락을 움직일 때, 그리고 마지막으로 Enum.UserInputState.End .

이 이벤트는 최소 2개의 손가락이 필요하기 때문에 에뮬레이터와 마우스를 사용하여 Studio에서 시뮬레이션할 수는 없습니다; 실제로 터치가 가능한 기기있어야 합니다.

매개 변수

touchPositions: Array

Luau 배열의 Vector2 개체, 각각 제스처와 관련된 모든 손가락의 위치를 나타냅니다.

rotation: number

제스처 시작 시점부터 회전이 얼마나 진행되었는지를 나타내는 부동 소수점입니다.

velocity: number

제스처가 얼마나 빨리 수행되는지를 나타내는 부동 소수점입니다.

제스처의 Enum.UserInputState를 나타냅니다.


코드 샘플

Touch Rotation

local innerFrame = script.Parent
local outerFrame = innerFrame.Parent
outerFrame.BackgroundTransparency = 0.75
outerFrame.Active = true
outerFrame.Size = UDim2.new(1, 0, 1, 0)
outerFrame.Position = UDim2.new(0, 0, 0, 0)
outerFrame.AnchorPoint = Vector2.new(0, 0)
outerFrame.ClipsDescendants = true
local dragging = false
local baseRotation = innerFrame.Rotation
local function onTouchRotate(_touchPositions, rotation, _velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
baseRotation = innerFrame.Rotation
outerFrame.BackgroundTransparency = 0.25
elseif state == Enum.UserInputState.Change then
innerFrame.Rotation = baseRotation + rotation
elseif state == Enum.UserInputState.End and dragging then
dragging = false
outerFrame.BackgroundTransparency = 0.75
end
end
outerFrame.TouchRotate:Connect(onTouchRotate)

TouchSwipe

이 이벤트는 터치 활성화 장치를 사용하여 UI 요소에 스와이프 제스처를 수행할 때 발생합니다. This event fires when the player performs a swipe gesture on the UI element using a touch-enabled device.감촉 방향(위, 아래, 왼쪽 또는 오른쪽)과 감촉 지점 수(터치 포인트)를 사용하여 발사합니다.스와이프 제스처는 종종 모바일 UI에서 탭을 변경하는 데 사용됩니다.

이 이벤트는 한 손가락만 필요하기 때문에, 스튜디오에서 에뮬레이터와 마우스를 사용하여 시뮬레이션할 수 있습니다.

매개 변수

swipeDirection: Enum.SwipeDirection

방향 스와이프 제스처(위, 아래, 왼쪽 또는 오른쪽)를 나타내는 A Enum.SwipeDirection

numberOfTouches: number

제스처에 관련된 터치 포인트 수(일반적으로 1).


코드 샘플

Bouncing Color Picker

local frame = script.Parent
frame.Active = true
-- How far the frame should bounce on a successful swipe
local BOUNCE_DISTANCE = 50
-- Current state of the frame
local basePosition = frame.Position
local hue = 0
local saturation = 128
local function updateColor()
frame.BackgroundColor3 = Color3.fromHSV(hue / 256, saturation / 256, 1)
end
local function onTouchSwipe(swipeDir, _touchCount)
-- Change the BackgroundColor3 based on the swipe direction
local deltaPos
if swipeDir == Enum.SwipeDirection.Right then
deltaPos = UDim2.new(0, BOUNCE_DISTANCE, 0, 0)
hue = (hue + 16) % 255
elseif swipeDir == Enum.SwipeDirection.Left then
deltaPos = UDim2.new(0, -BOUNCE_DISTANCE, 0, 0)
hue = (hue - 16) % 255
elseif swipeDir == Enum.SwipeDirection.Up then
deltaPos = UDim2.new(0, 0, 0, -BOUNCE_DISTANCE)
saturation = (saturation + 16) % 255
elseif swipeDir == Enum.SwipeDirection.Down then
deltaPos = UDim2.new(0, 0, 0, BOUNCE_DISTANCE)
saturation = (saturation - 16) % 255
else
deltaPos = UDim2.new()
end
-- Update the color and bounce the frame a little
updateColor()
frame.Position = basePosition + deltaPos
frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.7, true)
end
frame.TouchSwipe:Connect(onTouchSwipe)
updateColor()

TouchTap

이 이벤트는 터치 활성화 장치를 사용하여 UI 요소에서 탭 제스처를 수행할 때 발생합니다. This event fires when the player performs a tap gesture on the UI element using a touch-enabled device.탭은 어떤 움직임도 관련되지 않은 빠른 단일 터치입니다(더 길게 누르면 GuiObject.TouchLongPress가 발사되고, 터치 중에 이동하면 GuiObject.TouchPan와/또는 GuiObject.TouchSwipe가 발사됩니다).그것은 제스처에 관련된 손가락의 상대 위치를 설명하는 Vector2 개체의 테이블로 발사됩니다.

이 이벤트는 한 손가락만 필요하기 때문에, 스튜디오에서 에뮬레이터와 마우스를 사용하여 시뮬레이션할 수 있습니다.

매개 변수

touchPositions: Array

제스처와 관련된 손가락의 상대적인 위치를 설명하는 배열.


코드 샘플

Tap Transparency Toggle

local frame = script.Parent
frame.Active = true
local function onTouchTap()
-- Toggle background transparency
if frame.BackgroundTransparency > 0 then
frame.BackgroundTransparency = 0
else
frame.BackgroundTransparency = 0.75
end
end
frame.TouchTap:Connect(onTouchTap)