表面藝術

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

玩家們常常喜歡感覺自己是所處空間建設的一部分。 SurfaceArt 開發者模組 使用戶在體驗中真實地留下他們的印記。

模組使用

安裝

要在體驗中使用 SurfaceArt 模組:

  1. 從 Studio 的 視窗 菜單或 首頁 標籤工具欄中,打開 工具箱 並選擇 創作者商店 標籤。

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

  3. 找到並點擊 瓦片。

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

  5. 資源管理器 窗口中,將整個 SurfaceArt 模型移動到 ReplicatedStorage 中。運行體驗後,模組將開始運作。

放置畫布

該模組附帶一個 SurfaceCanvas 模型,可以在 3D 世界中進行定位。這個模型是玩家將與之互動以在其表面上放置藝術作品的對象。

  1. 在模組的主文件夾中找到 Workspace 文件夾內的 SurfaceCanvas 網格。

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

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

更改畫布面朝向

在底層,該模組使用 SurfaceGui 來顯示藝術項目。要配置藝術呈現在哪個面上:

  1. 選擇 SurfaceCanvas 網格。

  2. 屬性 窗口的底部,找到名稱為 SurfaceCanvasFace 的屬性,預設值為 右側

  3. 點擊該屬性並輸入描述 Enum.NormalId 的六個值中的一個。

使用自定義藝術資產

為了更好地配合您的體驗主題,您可以使用自己的自定義資產集,而不是默認資產。這可以通過從 ServerScriptService 中的 Script 調用的 configure 功能來完成。

Script

local 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 函數。

Script

local 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
assetsSurfaceArtAsset 類型的清單。(見 下方的程式碼)
quotaPerPlayer每位玩家可以放置的藝術品最大數量。2
Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
SurfaceArt.configure({
quotaPerPlayer = 4,
promptKeyCode = Enum.KeyCode.T,
promptMaxActivationDistance = 8,
})

getCanvases

getCanvases(): table

返回所有標記為 SurfaceCanvas 的畫布。

Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage.SurfaceArt)
local canvases = SurfaceArt.getCanvases()

placeArt

placeArt(player: Player, canvas: BasePart)

在玩家的名義下以程式方式放置藝術品。請注意,當伺服器初始化時,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()

從所有表面中移除所有藝術作品。

Script

local 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)
©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。