Studio 위젯 구축

스튜디오는 사용자 지정 위젯을 만들고 이를 스튜디오 도구 및 확장으로 사용할 수 있는 기능을 제공합니다. 이러한 위젯은 스튜디오에서 사용자 지정 창/패널로 작동하며 인터페이스 내부에 도킹하거나 별도의 창으로 띄울 수 있습니다.

위젯 UI 만들기

모든 스튜디오 위젯은 텍스트 레이블 및 버튼과 같이 GuiObjects(으)로 채울 수 있는 DockWidgetPluginGui개체로 시작합니다. 빈 위젯 GUI를 만들려면 CreateDockWidgetPluginGui()기능을 호출하고 ID와 개DockWidgetPluginGuiInfo체를 전달합니다.

DockWidgetPluginGuiInfo.new()제작자는 다음과 같은 특정 순서로 그 매개변수를 예상합니다.

#속성유형설명
1Enum.InitialDockState열거형Enum.InitialDockState열거 중 하나.
2InitialEnabled부울위젯 GUI의 초기 활성화(표시) 상태입니다.
3InitialEnabledShouldOverrideRestore부울참 인 경우 **초기 활성화 ** 값이 이전에 저장된 활성화 상태를 재정의합니다.
4FloatingXSize정수**초기 독 상태 **가 Enum.InitialDockState.Float(으)로 설정된 경우 GUI의 초기 폭입니다.
5FloatingYSize정수초기 독 상태Enum.InitialDockState.Float으로 설정되었을 때 GUI의 초기 높이입니다.
5MinWidth정수일부 플랫폼별 변형이 있는 GUI의 최소 폭입니다.
7MinHeight정수일부 플랫폼별 변형이 있는 GUI의 최소 높이입니다.

-- Create new "DockWidgetPluginGuiInfo" object
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float, -- Widget will be initialized in floating panel
true, -- Widget will be initially enabled
false, -- Don't override the previous enabled state
200, -- Default width of the floating window
300, -- Default height of the floating window
150, -- Minimum width of the floating window
150 -- Minimum height of the floating window
)
-- Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
testWidget.Title = "Test Widget" -- Optional widget title

위젯 UI 사용자 정의

위젯을 만들면 유익한 TextLabels또는 대화식 ImageButtons와(과)같은 GuiObjects을(를) 사용하여 위젯의 사용자 인터페이스를 사용자 지정할 수 있습니다. 예를 들어 다음 코드는 기본 TextButton을(를) GUI 창에 추가합니다.


-- Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
testWidget.Title = "Test Widget" -- Optional widget title
local testButton = Instance.new("TextButton")
testButton.BorderSizePixel = 0
testButton.TextSize = 20
testButton.TextColor3 = Color3.new(1,0.2,0.4)
testButton.AnchorPoint = Vector2.new(0.5,0.5)
testButton.Size = UDim2.new(1,0,1,0)
testButton.Position = UDim2.new(0.5,0,0.5,0)
testButton.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton.Text = "Click Me"
testButton.Parent = testWidget

Studio 색상 테마 변경

효과적인 스튜디오 위젯은 스튜디오 테마 설정과 이상적으로 일치하며 테마가 변경되면 동적으로 조정됩니다. 예를 들어 개발자가 어두운 테마를 사용하는 경우 위젯의 배경 색상, 이미지 및 텍스트 레이블이 스튜디오의 본래 테마 색상과 함께 보기 좋게 표시되어야 합니다.

다음 코드 추가는 초기에 동기화할 GUI 개체 테이블과 함께 호출되는 기syncGuiColors()능을 사용합니다. 기능 내에서 중첩된 setColors()기능은 개체를 반복하고 GetColor()와(과) 함께 Enum.StudioStyleGuideColor열거형을 사용하여 개체의 특정 측면을 동기화합니다. 이 setColors()기능은 곧바로 실행되어 스튜디오 테마를 동기화한 다음 ThemeChanged이벤트에 연결되어 향후 테마 변경을 감지합니다.


testButton.Parent = testWidget
local function syncGuiColors(objects)
local function setColors()
for _, guiObject in pairs(objects) do
-- Sync background color
guiObject.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
-- Sync text color
guiObject.TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText)
end
end
-- Run 'setColors()' function to initially sync colors
setColors()
-- Connect 'ThemeChanged' event to the 'setColors()' function
settings().Studio.ThemeChanged:Connect(setColors)
end
-- Run 'syncGuiColors()' function to sync colors of provided objects
syncGuiColors({testButton})

마우스 커서 사용자 지정

위젯 요소와의 예상되는 상호 작용을 개선하기 위해 시스템별 마우스 커서을(를) MouseEnterMouseLeave와(과) 같은 GUI 이벤트로 설정할 수 있습니다. 다음 코드는 기능을 MouseEnterMouseLeave및 이testButton벤트에 연결하여 마우스 커서를 변경하는 방법을 보여줍니다.


local function setCursor(cursorAsset)
plugin:GetMouse().Icon = cursorAsset
end
testButton.MouseEnter:Connect(function()
setCursor("rbxasset://SystemCursors/PointingHand")
end)
testButton.MouseLeave:Connect(function()
setCursor("")
end)

마우스 커서 목록과 가능한 사용의 예는 다음 표를 참조하세요.

마우스 커서 아이콘애셋사용 사례
rbxasset://SystemCursors/Arrow기본 클릭 및 선택
rbxasset://SystemCursors/PointingHand활성 링크/버튼 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/OpenHand드래그할 수 있는 항목 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/ClosedHand아이템을 드래깅합니다.
rbxasset://SystemCursors/IBeam텍스트 필드위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SizeNS세로 크기 조정 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SizeEW가로 크기 조정 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SizeNESW모서리 크기 조정 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SizeNWSE모서리 크기 조정 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SizeAll여러 방향 조정 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SplitNS세로 '분할' 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/SplitEW가로 '분할' 핸들 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/Forbidden잠긴/금지된 항목 위로 마우스를 가져갑니다.
rbxasset://SystemCursors/Wait작업이 진행 중임이 나타납니다.
rbxasset://SystemCursors/Busy 시스템이 바쁘다고 나타납니다.
rbxasset://SystemCursors/Cross정확한 선택 영역 위로 마우스를 가져갑니다.

사용자 입력 수집

TextBoxTextButton등의 UI 요소는 스튜디오 위젯에서 정상적으로 작동하며 Roblox에서 평소처럼 인터페이스를 구축할 수 있습니다. 하지만 UserInputServiceContextActionService은(는) 기본 게임 창에 초점이 맞춰져야 하기 때문에 작동하지 않습니다.

일반 입력 이벤트에 대한 한 가지 해결 방법은 투명한 Frame을(를) 만들어 전체 화면에 오버레이하는 것입니다. 다음 코드 샘플은 프레임을 생성하고 사용자가 프레임을 클릭하면 GuiObject.InputBegan이벤트는 사용자가 클릭할 때까지 프레임의 키보드 입력을 캡처합니다.


local frame = Instance.new("Frame")
frame.BackgroundTransparency = 1 -- Hide the frame
frame.Size = UDim2.new(1, 0, 1, 0) -- Cover the screen
frame.Position = UDim2.new(0, 0, 0, 0)
frame.Parent = testWidget
local function onInputBegan(inputObject)
-- Process the input object here, for example detect key presses
end
frame.InputBegan:Connect(onInputBegan)

드래그 앤 드롭 상호 작용

위젯에 드래그 앤 드롭 상호 작용을 사용하는 것은 데이터 흐름을 개선하는 간단한 방법입니다. 이 상호 작용을 생성하려면 드래깅할 요소를 정의하고, 드래깅을 시작하고, 드롭 대상을 생성하고, 드롭 동작을 처리해야 합니다.

드래깅 소스 생성

Plugin:StartDrag()을(를) 호출하여 사용자가 일부 UI 요소(일반적으로 위젯 내의 또TextButton는)ImageButton 드래깅을 시작할 수 있습니다. 다음 코드 샘플은 내부에 텍스트 버튼이 있는 단일 창 위젯을 만듭니다.


-- Create the widget first
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
-- Create a TextButton that will initiate the drag
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, 0)
dragButton.Text = "Drag me!" dragButton.Parent = dragSourceWidget

드래깅 시작

사용자가 TextButton을 클릭하면 마우스 버튼을 누르는 즉시 발생하는 이MouseButton1Down()벤트를 통해 드래깅을 시작할 수 있습니다.

연결된 기능 내에서 드래깅할 데이터를 결정합니다. 데이터 유형MimeType키에 반영되어야 하고 드래깅 콘텐츠Data키에 반영되어야 하며 보낸 사람Sender 키에 자신을 설명해야 합니다. 자세한 내용은 페이지 Plugin:StartDrag()을(를) 참조하십시오.


local function onButton1Down()
local dragInfo = {
Data = "Hello, world", -- The data being dragged
MimeType = "text/plain", -- Describes the MIME type of the data
Sender = "SomeDragSource", -- Describes from where the data originated
MouseIcon = "", -- Image content to use for the cursor
DragIcon = "", -- Image content to render under the cursor during drag
HotSpot = Vector2.new(0, 0) -- Where on the DragIcon to center the cursor
}
plugin:StartDrag(dragInfo)
end
dragButton.MouseButton1Down:Connect(onButton1Down)

드롭 대상 생성

PluginGui.PluginDragDropped의 이벤트는 사용자가 드래깅하는 동안 창에서 마우스를 놓으면 발생합니다. 이런 일이 발생하면 TextLabel이 있는 두 번째 위젯과 같은 드롭 대상을 정의하여 드롭을 감지해야 합니다.


local dragTargetWidget = plugin:CreateDockWidgetPluginGui("Drop Target", widgetInfo)
dragTargetWidget.Title = "Drop Target"
-- This TextLabel will display what was dropped
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Drop here..." textLabel.Parent = dragTargetWidget

드롭 작업 처리

드롭 대상을 만든 후 드롭 대상 위젯 PluginGui.PluginDragDropped이벤트를 연결합니다.


local function onDragDrop(dragData)
print("PluginDragDropped")
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)

드래깅이 진행 중인 동안 사용자가 위젯 위로 마우스를 이동하면 이 세 가지 이벤트가 발생합니다.

  • PluginDragEntered- 사용자가 창 위로 마우스를 가져가면 실행됩니다.
  • PluginDragLeft- 사용자의 커서가 창을 떠날 때 발생합니다. 이것은 "여기에 놓으시오!"메시지를 숨기는데 유용합니다.
  • PluginDragLeft – 사용자의 커서가 창을 떠날 때 발생합니다. 이것은 "여기에 놓으시오!" 메시지를 표시하는 데 유용합니다.