玩家通常喜欢感到自己是正在构建的空间的一部分。SurfaceArt 开发者模块 让玩家在体验中真正留下自己的印记。
模块用法
安装
要在体验中使用 SurfaceArt 模块:
从 Studio 的 窗口 菜单或 首页 标签工具栏中,打开 工具箱 并选择 创作者商店 标签。

确保选择了 模型 排序,然后单击 查看全部 按钮以查看 类别。

找到并单击 包 瓷砖。
找到 表面艺术 模块并单击它,或将其拖放到 3D 视图中。

在 资源管理器 窗口中,将整个 SurfaceArt 模型移动到 ReplicatedStorage 中。运行体验后,模块将开始运行。
定位画布
该模块带有一个 SurfaceCanvas 模型,可以在 3D 世界中定位。玩家将与此模型交互以在其表面上放置艺术作品。
在模块的主文件夹中找到 Workspace 文件夹中的 SurfaceCanvas 网格。

将其移动到顶层 Workspace 结构中,并根据需要定位。

在发布/运行测试会话时,玩家将能够通过 ProximityPrompt 与对象互动,并在定义的表面上放置艺术作品。

更改画布面
在模块内部,使用 SurfaceGui 来显示艺术项目。要配置艺术出现的表面:
选择 SurfaceCanvas 网格。
在 属性 窗口的底部,找到默认值为 右 的 SurfaceCanvasFace 属性。

单击属性并输入描述 Enum.NormalId 的六个值之一。
| 属性值 | 对应的正常 ID |
|---|---|
| 前 | Enum.NormalId.Front |
| 后 | Enum.NormalId.Back |
| 右 | Enum.NormalId.Right |
| 左 | Enum.NormalId.Left |
| 顶部 | Enum.NormalId.Top |
| 底部 | Enum.NormalId.Bottom |
使用自定义艺术资源
为了更好地契合您体验的主题,您可以使用自己的一组自定义资源,而不是默认值。这可以通过在 ServerScriptService 中的 Script 中调用 configure 函数来完成。
脚本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 函数。
脚本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 |
| assets | 类型为 SurfaceArtAsset 的资源列表。 | (见 下面的代码) |
| quotaPerPlayer | 每个玩家可以放置的艺术作品的最大数量。 | 2 |
脚本local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)SurfaceArt.configure({quotaPerPlayer = 4,promptKeyCode = Enum.KeyCode.T,promptMaxActivationDistance = 8,})
getCanvases
getCanvases(): table
返回所有标记为 SurfaceCanvas 的画布。
脚本local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)local canvases = SurfaceArt.getCanvases()
placeArt
代表玩家以编程方式放置艺术作品。请注意,canvas 对象必须在服务器初始化时被标记为 SurfaceCanvas。建议仅在 getCanvases 返回的画布上使用此功能。
脚本
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()
从所有表面上移除所有艺术作品。
脚本local ReplicatedStorage = game:GetService("ReplicatedStorage")local SurfaceArt = require(ReplicatedStorage.SurfaceArt)SurfaceArt.removeAllArt()
事件
artChanged
当在画布的特定位置更改艺术作品时触发。当艺术作品被移除时,artId 将为 nil。注意,第三个参数传递了一个 Vector3 值,以便您可以在艺术作品放置的确切位置上定位 自定义效果。此事件只能在 LocalScript 中连接。
| 参数 | |
|---|---|
| canvas: BasePart | 艺术作品更改的画布。 |
| spot: Frame | 包含艺术作品 ImageLabel 的内部 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)