表面艺术

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

玩家经常喜欢感觉自己是参与建造自己所在空间的一部分。表面艺术 开发者模块 允许玩家在体验中文字地离开他们的标记。

模块使用

安装

要在体验中使用 表面艺术 模块:

  1. 视图选项卡打开工具箱并选择 创建者商店 选项卡。

    Toolbox toggle button in Studio
  2. 确保 模型 排序已选择,然后单击 查看全部 按钮以获取 类别

  3. 找到并单击 开发模块 瓦片。

  4. 找到 表面艺术 模块并单击它,或拖放到 3D 视查看中。

  5. 浏览器 窗口中,将整个 表面艺术 模型移至 ServerScriptService 。在运行体验时,模块将分配到各种服务并开始运行。

放置画布

模块带有一个 表面画布 模型,您可以在 3D 世界中放置。这个模型是玩家与之交互放置艺术的表面。

  1. 找到模块主文件夹内的 表面画布 网格内的 工作区 文件夹。

  2. 将其移至顶层 工作区 架构中,并将其放置在所需位置。

  3. 发布/运行测试会话后,玩家可以通过一个 ProximityPrompt 与对象进行互动,并将艺术放置在定义的表面上。

更改画布面

在引擎底部,模块使用 SurfaceGui 来显示艺术项目。要配置艺术出现在哪个表面上:

  1. 选择 表面画布 网格。

  2. 属性 窗口的底部,找到 表面画布面 属性的默认值为 右侧 的值。

  3. 单击属性,然后输入描述 Enum.NormalId 的六个值之一。

使用自定义艺术资产

为了更好地适应您的体验主题,您可以使用自己的一组自定义资产而不是默认值。这可以通过 配置 函数来实现,从 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 参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()

放置艺术

放置艺术(玩家: Player , 画布: BasePart )

在玩家名义上程序地放置一件艺术作品。注意,当服务器初始化时,canvas 对象必须使用 SurfaceCanvas 标签标记。建议仅使用此与从 getCanvases 返回的 canvas 进行交互。

脚本

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
local remoteEvent = ReplicatedStorage:WaitForChild("SurfaceArtRemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player)
-- 将默认艺术资产的 Bloxy 奖从第一个画布放入第一个画布
local canvases = SurfaceArt.getCanvases()
SurfaceArt.placeArt(player, canvases[1], "BloxyAward")
end)

移除所有艺术

移除所有艺术()

移除所有艺术品从所有表面。

脚本

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SurfaceArt = require(ReplicatedStorage:WaitForChild("SurfaceArt"))
SurfaceArt.removeAllArt()

事件

艺术变更

在画布上的特定位置更改艺术作品时发生火焰。当一个艺术品被移除时,artId将是nil。请注意,一个 Vector3 值被传递为事件处理器的第三个参数,以便您在艺术作品放置的准确位置放置 自定义效果。此事件只能在 LocalScript 中连接。

参数
画布:BasePart艺术作品更改的画布。
位置:Frame内部 Frame 包含作品 ImageLabel
斑点位置:Vector3艺术作品放置的准确位置。
艺术ID:string新艺术作品的资产 ID。
所有者用户ID: numberUserId 放置艺术的玩家。
本地脚本

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)