玩家經常喜歡覺得自己是參與建造自己所在空間的一部分。表面藝術 開發模組 讓玩家在體驗中實際地留下標記。
模組使用
安裝
要在體驗中使用 表面藝術 模組:
確保 模型 排序已選擇,然後單擊 查看全部 按鈕以獲得 類別 。
找到並點擊 開發模組 磚塊。
找到 表面藝術 模組,然後單擊它或拖放到 3D 視檢視中。
在 檢索器 窗口中,將整個 SurfaceArt 模型移動到 ServerScriptService 。執行體驗時,模組會分配到各種服務並開始運行。
位置化畫布
模組包含一個 表面繪圖 模型,您可以在 3D 世界中定位。這個模型是玩家會與之互動放置藝術在其表面的東西。
在模組主目錄的 工作區 文件夾內尋找 表面繪圖網格 網格。
將它移動到最高級 工作區 層次並將其放置在所需位置。
發布/執行測試會作業後,玩家將能夠通過 ProximityPrompt 與對象進行互動,並將藝術放置在定義的表面上。
變更畫布面
在引擎底下,模組使用 SurfaceGui 來顯示藝術項目。要配置藝術出現在哪個表面:
選擇 表面繪圖 網格。
在 屬性 窗口底部,尋找具有預設值 右 的 表面繪圖面 特性。
點擊屬性並輸入描述 Enum.NormalId 的六種值之一。
特性值 | 對應的普通 ID |
---|---|
前 | Enum.NormalId.Front |
返回 | Enum.NormalId.Back |
右 | Enum.NormalId.Right |
左 | Enum.NormalId.Left |
顶部 | Enum.NormalId.Top |
底部 | Enum.NormalId.Bottom |
使用自訂藝術資產
為了更好地符合您體驗的主題,您可以使用自己的集合化定制資產,而不是預設值。這可以通過 配置 功能來完成,從 ServerScriptService 中呼叫。
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))local customAssets = {CustomAsset1 = {name = "Custom Asset 1",assetId = "rbxassetid://7322508294",},CustomAsset2 = {name = "Custom Asset 2",assetId = "rbxassetid://7322547665",},}SurfaceArt.configure({assets = customAssets,})
清除所有畫布
要從世界上所有畫布中移除所有現有的藝術,請從 removeAllArt 函數中呼叫 Script 。
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))SurfaceArt.removeAllArt()
顯示自訂效果
可能有情況需要在放置藝術作品時包含額外的視覺效果。這個模組在客戶端暴露一個名為 artChanged 的事件,您可以連接並添加自己的邏輯。
本地脚本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("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 參考
類型
表面藝術資產
要用於畫布的圖像以兩個值來表示一個表。
關鍵 | 說明 |
---|---|
name | 元資料顯示名稱。 |
assetId | 要包含的圖像資產ID。 |
功能
設定
設定(config: table )
通過以下鍵/值在 config 表中覆蓋預設配置選項的默認選項。此功能只能從 Script 中呼叫。
關鍵 | 說明 | 預設 |
---|---|---|
enabled | 切換模組的功能是否開啟或關閉。 | 真的 |
assets | 列出 表面藝術資產 類型的列表。 | (見下方代碼) |
quotaPerPlayer | 每位玩家可放置的藝術作品最大數量。 | 2 |
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))SurfaceArt.configure({quotaPerPlayer = 4,promptKeyCode = Enum.KeyCode.T,promptMaxActivationDistance = 8,})
取得畫布
getCanvases(): table
返回標有 SurfaceCanvas 標籤的所有畫布。
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))local canvases = SurfaceArt.getCanvases()
放置Art
代表玩家程式性地放置一件藝術作品。請注意,當服務器初始化時, canvas 對象必須使用 SurfaceCanvas 標籤標記。建議只使用此功能與從 getCanvases 返回的畫布一起使用。
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
local remoteEvent = ReplicatedStorage:WaitForChild("SurfaceArtRemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player)
-- 將從預設藝術資產中獲得的布洛克獎放置到第一個畫布上
local canvases = SurfaceArt.getCanvases()
SurfaceArt.placeArt(player, canvases[1], "BloxyAward")
end)
移除所有藝術
移除所有文件()
移除所有藝術品的所有表面。
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))SurfaceArt.removeAllArt()
事件
art變更
在畫布上的特定位置更改作品時發生火災。當一幅藝術品被移除時,artId將是nil。請注意,Vector3被傳送到事件處理器作為第三個參數,以便您在作品放置的準確位置放置自訂效果。此事件只能在 LocalScript 中連接。
參數 | |
---|---|
畫布:BasePart | 是畫作變更的畫布。 |
點: Frame | 內部 Frame 包含作品 ImageLabel。 |
點位置:Vector3 | 藝術品放置的準確位置。 |
藝術ID:string | 新藝術作品的資產 ID。 |
擁有者ID: number | UserId 放置藝術的玩家。 |
本地脚本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
SurfaceArt.artChanged:Connect(function(canvas, spot, spotPosition, artId, ownerId)
print("Art placed at:", spotPosition)
print("Art asset ID:", artId)
print("Art placed by:", ownerId)
end)
快速顯示
當畫布互動提示向玩家顯示時,發生火災。連接的功能會收到提示顯示的畫布。此事件只能在 LocalScript 中連接。
參數 | |
---|---|
畫布:BasePart | 畫布,在畫布上顯示提示。 |
本地脚本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
SurfaceArt.promptShown:Connect(function(canvas)
print(Players.LocalPlayer, canvas)
end)
快捷隱藏
當繪圖互動提示隱藏時發生火災。連接的功能會收到提示顯示的畫布。此事件只能在 LocalScript 中連接。
參數 | |
---|---|
畫布:BasePart | 是指顯示提示的畫布。 |
本地脚本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
SurfaceArt.promptClosed:Connect(function(canvas)
print(Players.LocalPlayer, canvas)
end)
選擇器顯示
當顯示給玩家的表面藝術選擇器 UI 時發生火災。此事件只能在 LocalScript 中連接。
本地脚本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
SurfaceArt.selectorShown:Connect(function()
print(Players.LocalPlayer, "opened surface art selector")
end)
隱藏選擇器
在玩家隱藏表面藝術選擇器 UI 時發生火災。此事件只能在 LocalScript 中連接。
本地脚本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
SurfaceArt.selectorHidden:Connect(function()
print(Players.LocalPlayer, "closed surface art selector")
end)