學習
引擎類別
PluginConnectionService
無法建立
服務
未複製

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


範例程式碼
PluginConnection 回音插件
local Service = game:GetService("PluginConnectionService")
local TestType = Enum.PluginConnectionTargetType.Test
local EditType = Enum.PluginConnectionTargetType.Edit
local function MakeConnection(Connection: PluginConnection, Side: string)
assert(Connection.Connected)
local Count = 0
local Binding = Connection:BindToMessage(function(Msg: string)
print(Msg)
task.wait(1)
if Connection.Connected then
Connection:SendMessage(`來自 {Side} 的消息,第 {Count} 次`)
end
Count += 1
end)
plugin.Unloading:Connect(function()
Binding:Disconnect()
end)
Connection:GetPropertyChangedSignal("Connected"):Once(function()
assert(not Connection.Connected)
print("已斷開連接", Connection.TargetId)
end)
end
if Service:CanHaveConnectionType(TestType) then
for _, ExistingConnection in Service:GetPluginConnectionsOfType(TestType) do
MakeConnection(ExistingConnection, "Edit")
end
Service.Connected:Connect(function(NewConnection)
if NewConnection.Type == TestType then
MakeConnection(NewConnection, "Edit")
end
end)
elseif Service:CanHaveConnectionType(EditType) then
local Connections = Service:GetPluginConnectionsOfType(EditType)
assert(#Connections <= 1)
local Connection: PluginConnection? = nil
if #Connections == 1 then
Connection = Connections[1]
else
while true do
local NewConnection = Service.Connected:Wait()
if NewConnection.Type == EditType then
Connection = NewConnection
break
end
end
end
assert(Connection)
assert(Connection.Connected)
MakeConnection(Connection, if game:GetService("RunService"):IsServer() then "伺服器" else "客戶端")
Connection:SendMessage("你好,編輯!")
end

API 參考
方法
CanHaveConnectionType
外掛程式安全性
PluginConnectionService:CanHaveConnectionType(type:Enum.PluginConnectionTargetType):boolean
返回

GetPluginConnectionsOfType
外掛程式安全性
PluginConnectionService:GetPluginConnectionsOfType(type:Enum.PluginConnectionTargetType):{PluginConnection}

活動
Connected
外掛程式安全性
PluginConnectionService.Connected(conn:PluginConnection):RBXScriptSignal
參數

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。