玩家們常常喜歡感覺自己是所處空間建設的一部分。 SurfaceArt 開發者模組 使用戶在體驗中真實地留下他們的印記。
模組使用
安裝
要在體驗中使用 SurfaceArt 模組:
從 Studio 的 視窗 菜單或 首頁 標籤工具欄中,打開 工具箱 並選擇 創作者商店 標籤。

確保已選擇 模型 排序,然後點擊 查看所有 按鈕以顯示 類別。

找到並點擊 包 瓦片。
找到 表面藝術 模組並點擊它,或將其拖放到 3D 視圖中。

在 資源管理器 窗口中,將整個 SurfaceArt 模型移動到 ReplicatedStorage 中。運行體驗後,模組將開始運作。
放置畫布
該模組附帶一個 SurfaceCanvas 模型,可以在 3D 世界中進行定位。這個模型是玩家將與之互動以在其表面上放置藝術作品的對象。
在模組的主文件夾中找到 Workspace 文件夾內的 SurfaceCanvas 網格。

將其移動到頂級 Workspace 層級,並按需定位。

在發布 / 運行測試會話後,玩家將能夠通過 ProximityPrompt 與該對象進行互動並在定義的表面上放置藝術品。

更改畫布面朝向
在底層,該模組使用 SurfaceGui 來顯示藝術項目。要配置藝術呈現在哪個面上:
選擇 SurfaceCanvas 網格。
在 屬性 窗口的底部,找到名稱為 SurfaceCanvasFace 的屬性,預設值為 右側。

點擊該屬性並輸入描述 Enum.NormalId 的六個值中的一個。
| 屬性值 | 對應的 Normal ID |
|---|---|
| 前面 | Enum.NormalId.Front |
| 後面 | Enum.NormalId.Back |
| 右側 | Enum.NormalId.Right |
| 左側 | Enum.NormalId.Left |
| 頂部 | Enum.NormalId.Top |
| 底部 | Enum.NormalId.Bottom |
使用自定義藝術資產
為了更好地配合您的體驗主題,您可以使用自己的自定義資產集,而不是默認資產。這可以通過從 ServerScriptService 中的 Script 調用的 configure 功能來完成。
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)local customAssets = {CustomAsset1 = {name = "自定義資產 1",assetId = "rbxassetid://7322508294",},CustomAsset2 = {name = "自定義資產 2",assetId = "rbxassetid://7322547665",},}SurfaceArt.configure({assets = customAssets,})
清除所有畫布
要移除世界中所有畫布上的現有藝術作品,請從 Script 調用 removeAllArt 函數。
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)SurfaceArt.removeAllArt()
顯示自定義效果
可能會有一些情況,您想要在放置藝術品時包含額外的視覺效果。此模組在客戶端上公開一個名為 artChanged 的事件,您可以連接到該事件並添加自己的邏輯。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
local function createParticleEmitter(canvas, position)
local attachment = Instance.new("Attachment")
attachment.Position = canvas.CFrame:PointToObjectSpace(position)
attachment.Axis = Vector3.new(0, 0, 1)
attachment.SecondaryAxis = Vector3.new(1, 0, 0)
attachment.Parent = canvas
local particleEmitter = Instance.new("ParticleEmitter")
particleEmitter.Speed = NumberRange.new(50)
particleEmitter.Rate = 50
particleEmitter.Color = ColorSequence.new(Color3.fromRGB(128, 254, 7))
particleEmitter.SpreadAngle = Vector2.new(35, 35)
particleEmitter.Parent = attachment
return attachment
end
SurfaceArt.artChanged:Connect(function(canvas, spot, spotPosition, artId, ownerId)
if artId then
-- 顯示一些閃爍效果 3 秒
task.spawn(function()
local emitterAttachment = createParticleEmitter(canvas, spotPosition)
task.wait(3)
emitterAttachment:Destroy()
end)
end
end)
API 參考
類型
SurfaceArtAsset
用於畫布的藝術圖像由具有兩個值的表表示。
| 鍵 | 描述 |
|---|---|
| name | 元數據顯示名稱。 |
| assetId | 要包含的圖像資產 ID。 |
函數
configure
configure(config: table)
通過 config 表中的以下鍵/值覆蓋默認配置選項。此函數只能從 Script 調用。
| 鍵 | 描述 | 默認值 |
|---|---|---|
| enabled | 開關模組的功能。 | true |
| assets | SurfaceArtAsset 類型的清單。 | (見 下方的程式碼) |
| quotaPerPlayer | 每位玩家可以放置的藝術品最大數量。 | 2 |
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)SurfaceArt.configure({quotaPerPlayer = 4,promptKeyCode = Enum.KeyCode.T,promptMaxActivationDistance = 8,})
getCanvases
getCanvases(): table
返回所有標記為 SurfaceCanvas 的畫布。
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)local canvases = SurfaceArt.getCanvases()
placeArt
在玩家的名義下以程式方式放置藝術品。請注意,當伺服器初始化時,canvas 對象必須標記為 SurfaceCanvas。建議僅將此用於從 getCanvases 返回的畫布。
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
local remoteEvent = ReplicatedStorage:WaitForChild("SurfaceArtRemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player)
-- 將默認藝術資產中的 Bloxy 獎項放入第一個畫布中
local canvases = SurfaceArt.getCanvases()
SurfaceArt.placeArt(player, canvases[1], "BloxyAward")
end)
removeAllArt
removeAllArt()
從所有表面中移除所有藝術作品。
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)SurfaceArt.removeAllArt()
事件
artChanged
當藝術作品在畫布的特定位置被更改時觸發。當藝術作品被移除時,artId 將為 nil。注意,在事件處理器中傳遞了一個 Vector3 值作為第三個參數,以便您可以在藝術作品放置的確切位置上放置 自定義效果。此事件只能在 LocalScript 中連接。
| 參數 | |
|---|---|
| canvas: BasePart | 藝術作品變更的畫布。 |
| spot: Frame | 包含藝術作品的內部 Frame。 |
| spotPosition: Vector3 | 藝術品放置的確切位置。 |
| artId: string | 新藝術作品的資產 ID。 |
| ownerUserId: number | 放置藝術品的玩家的 UserId。 |
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
SurfaceArt.artChanged:Connect(function(canvas, spot, spotPosition, artId, ownerId)
print("藝術品放置於:", spotPosition)
print("藝術資產 ID:", artId)
print("藝術品由:", ownerId, "放置")
end)
promptShown
當畫布互動提示顯示給玩家時觸發。連接的函數接收正在顯示提示的畫布。此事件只能在 LocalScript 中連接。
| 參數 | |
|---|---|
| canvas: BasePart | 正在顯示提示的畫布。 |
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
SurfaceArt.promptShown:Connect(function(canvas)
print(Players.LocalPlayer, canvas)
end)
promptHidden
當畫布互動提示隱藏時觸發。連接的函數接收正在顯示提示的畫布。此事件只能在 LocalScript 中連接。
| 參數 | |
|---|---|
| canvas: BasePart | 正在顯示提示的畫布。 |
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
SurfaceArt.promptClosed:Connect(function(canvas)
print(Players.LocalPlayer, canvas)
end)
selectorShown
當表面藝術選擇器 UI 顯示給玩家時觸發。此事件只能在 LocalScript 中連接。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
SurfaceArt.selectorShown:Connect(function()
print(Players.LocalPlayer, "打開了表面藝術選擇器")
end)
selectorHidden
當表面藝術選擇器 UI 對玩家隱藏時觸發。此事件只能在 LocalScript 中連接。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
SurfaceArt.selectorHidden:Connect(function()
print(Players.LocalPlayer, "關閉了表面藝術選擇器")
end)