PluginGui

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
複製されていません

PluginGui は、様々な Roblox Studio ウィジェットで GuiObjects の表示を可能にするGUIの抽象クラスです。現時点で利用可能な唯一の PluginGui タイプは DockWidgetPluginGui ですが、将来はもっと多くなるかもしれません!

概要

プロパティ

LayerCollector から継承した プロパティGuiBase2d から継承した プロパティ

方法

イベント

GuiBase2d から継承した イベント

プロパティ

Title

並列読み取り

The title that is displayed above the contents of the PluginGui 。デフォルトで空の文字列になります。

方法

BindToClose

()

この関数は、機能を PluginGui 閉じるボタンにバインドし、デフォルトの動作を上書きします。

デフォルトでは、ユーザーが右上隅の PluginGui プロパティの 'x' ボタンをクリックすると、Enabled プロパティが 偽り に設定され、ウィンドウが閉じます。カスタム関数を BindToClose を使用してバインドすると、この動作が上書きされ、ユーザーが本当にウィンドウを閉じるか、作業を保存する機会を与えたいかどうかをチェックできます。

デフォルトの閉じる動作がこの関数によって上書きされるため、PluginGui を手動で閉じるように設定して PluginGui.Enabledfalse に設定する必要があります。たとえば、以下のスニペットでは、ユーザーが確認ボタンをクリックしてGUIを閉じる必要があります:


local closing = false
pluginGui:BindToClose(function()
-- すでにボタンを作成していないことを確認する
if closing then
return
end
closing = true
-- 作成確認ボタンを作成する
local confirmButton = Instance.new("TextButton")
confirmButton.AnchorPoint = Vector2.new(0.5, 0.5)
confirmButton.Size = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.Position = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.BackgroundColor3 = Color3.new(1, 0, 0)
confirmButton.Text = "Close?"
confirmButton.Parent = pluginGui
-- クリックを聞く
confirmButton.Activated:Connect(function()
-- gui を閉じる
pluginGui.Enabled = false
-- 削除確認ボタンを削除
confirmButton:Destroy()
end)
end)

BindToClose に引数を与えずに 'unbind' し、上記の説明されたデフォルトの動作に戻すことができます。たとえば:


pluginGui:BindToClose()

参照してください:

パラメータ

function: function

閉じるボタンにバインドする機能。機能が指定されていない場合は、以前に指定された機能が解除されます。

既定値: "nil"

戻り値

()

GetRelativeMousePosition

プラグインのセキュリティ

GetRelativeMousePosition は、PluginGui の左上隅に対するマウスの位置を返します。返された値は、プラグインGUI にマウス入力が開始したか、または現在マウスがウィンドウ上にホバーしている場合にのみ変更されます。


戻り値

ピクセルで PluginGui に対するマウスの画面位置。

コードサンプル

PluginGui:GetRelativeMousePosition

local RunService = game:GetService("RunService")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
true,
false, -- Enabled state, override
200,
300, -- Size
150,
150 -- Minimum size
)
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
function update()
local v2 = testWidget:GetRelativeMousePosition()
testWidget.Title = ("(%d, %d)"):format(v2.x, v2.y)
end
RunService.Stepped:Connect(update)
update()

イベント

PluginDragDropped

プラグインのセキュリティ

PluginDragDropped は、ユーザーが で始まったドラッグ操作中にマウスをリリースすると発動します。

参照してください:

パラメータ

dragData: Dictionary

コードサンプル

This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.

To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
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
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)

PluginDragEntered

プラグインのセキュリティ

PluginDragEntered は、PluginGui によって開始されたドラッグ操作中に、ユーザーのマウスが Plugin:StartDrag() に入ると発動します。

このイベントは、ドラッグ操作をドロップできる PluginGuis で「ここにドロップ」UIを表示するのに便利です。このような UI は、PluginDragLeft または PluginDragDropped 発射するときに非表示になるべきです。

参照してください:

パラメータ

dragData: Dictionary

元々 Plugin:StartDrag() に渡されたデータのコピー。


コードサンプル

This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.

To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
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
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)

PluginDragLeft

プラグインのセキュリティ

PluginDragLeft は、ユーザーのマウスが PluginGui によるドラッグ操作を開始したときに発動し、Plugin:StartDrag() によるドラッグ操作が終了すると発動します。

このイベントと PluginDragDropped は、ドラッグ操作をドロップできる PluginGuis の "ここにドロップ" UIを非表示にするのに便利です。このような UI は、PluginDragEntered が発動したときに表示されるべきです。

参照してください:

パラメータ

dragData: Dictionary

元々 Plugin:StartDrag() に渡されたデータのコピー。


コードサンプル

This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.

To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
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
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)

PluginDragMoved

プラグインのセキュリティ

PluginDragMoved は、PluginGui によって開始されたドラッグ操作中に、ユーザーのマウスが Plugin:StartDrag() 内移動すると発動します。

参照してください:

パラメータ

dragData: Dictionary

WindowFocusReleased

プラグインのセキュリティ

WindowFocusReleased は、ユーザーがプラグインGUIのウィンドウとの対話を停止すると、通常ウィンドウに含まれないものをクリックするとすぐに発射します。この機能は、同じく名前の UserInputService.WindowFocusReleased イベントと同様に機能します。

ユーザーがこのプラグインGUIをフォーカスにしている間、焦点が別の PluginGui に移動した場合、このイベントは、他のイベントの WindowFocused より前に発動します。しかし、メインゲームウィンドウが焦点に置かれている場合、このイベントは 後の UserInputService.WindowFocused に発火します。


コードサンプル

This code sample demonstrates how the focus state of a PluginGui can be tracked using the WindowFocused() and WindowFocusReleased() events. It changes the Title() as the focus state changes.

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)

WindowFocused

プラグインのセキュリティ

ウィンドウが焦点になった は、ユーザーが PluginGui のウィンドウと対話を開始するとすぐに発火し、通常はクリックして発生します。この機能は、同じく名前の UserInputService.WindowFocused イベントと同様に機能します。マウスボタンに関連するすべての GuiObject.InputBegan イベントが発生する前に発射します。

もう一つの PluginGui が焦点にあり、ユーザーがこの PluginGui に焦点を合わせている場合、このイベントは他のイベントの WindowFocusReleased 後に発動します。しかし、メインゲームウィンドウが焦点にあった場合、このイベントは 後の UserInputService.WindowFocusReleased に発射します。


コードサンプル

This code sample demonstrates how the focus state of a PluginGui can be tracked using the WindowFocused() and WindowFocusReleased() events. It changes the Title() as the focus state changes.

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)