拍攝照片是紀念美好經歷的完美方式。PhotoBooth 開發者模組 是一個易於使用的照片場景工具,讓玩家與代表他們經歷的背景擺出獨特的姿勢。
模組使用
安裝
要在體驗中使用 PhotoBooth 模組:
從 Studio 的 視窗 菜單或 首頁 標籤工具欄,打開 工具箱 並選擇 創作者商店 標籤。

確保選擇了 模型 排序,然後點擊 查看所有 按鈕以獲取 類別。

找到並點擊 套件 磁磚。
找到 照相亭 模組並點擊它,或拖放到 3D 視圖中。

在 資源管理器 窗口中,將整個 PhotoBooth 模型移動到 ReplicatedStorage。在運行體驗時,模組將開始運行。
擺放亭子
該模組附帶一個 PhotoBooth 模型,您可以在 3D 世界中擺放。這個模型是玩家互動以設置照片的對象。
在模組的主文件夾的 Workspace 文件夾中找到 PhotoBooth 網格。

將其移動到頂層的 Workspace 層級並擺放到所需位置。

配置
該模組已預配置以適應大多數用例,但可以通過 配置 函數輕鬆自定義。例如,要更改照片底部的默認消息:
在 StarterPlayerScripts 中,創建一個新的 LocalScript,並將其重命名為 ConfigurePhotoBooth。

將以下代碼粘貼到新腳本中。
LocalScript - ConfigurePhotoBoothlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local PhotoBooth = require(ReplicatedStorage.PhotoBooth)PhotoBooth.configure({frameMessage = "第一次照相亭捕捉!",})
連接事件
每當照相亭顯示新的屏幕給本地客戶端時,將觸發相應的事件。這些事件可以在 LocalScript 中連接,以便您可以用自定義邏輯響應。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhotoBooth = require(ReplicatedStorage.PhotoBooth)
PhotoBooth.countdownStarted:Connect(function()
print("倒計時已開始")
end)
PhotoBooth.printoutShown:Connect(function()
print("打印件顯示中")
end)
PhotoBooth.promptShown:Connect(function()
print("攝像頭提示顯示中")
end)
GUI 可見性
默認情況下,當照片被擺放時,照相亭隱藏所有 ScreenGuis 和 CoreGuis。如果您希望覆蓋此自動隱藏行為,並以編程方式決定哪些 GUI 應保持可見,請包含 hideOtherGuis 和 showOtherGuis 回調並用您的自定義邏輯做出反應。
LocalScript
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local PhotoBooth = require(ReplicatedStorage.PhotoBooth)
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local hiddenInstances = {}
-- 創建不會被隱藏的屏幕 GUI
local specialGuiInstance = Instance.new("ScreenGui")
-- 在照相亭 GUI 上方繪製選定的屏幕 GUI
specialGuiInstance.DisplayOrder = 1
specialGuiInstance.Parent = playerGui
-- 設置屏幕 GUI 的屬性以防止隱藏
specialGuiInstance:SetAttribute("ShowInPhotoBooth", true)
-- 向 GUI 添加文本標籤
local specialLabel = Instance.new("TextLabel")
specialLabel.Size = UDim2.fromScale(1, 0.1)
specialLabel.Text = "拍照時保持可見"
specialLabel.Font = Enum.Font.GothamMedium
specialLabel.TextSize = 24
specialLabel.Parent = specialGuiInstance
PhotoBooth.hideOtherGuis(function()
-- 隱藏所有開發者定義的屏幕 GUI,除了那些帶有屬性的
local instances = playerGui:GetChildren()
for _, instance in instances do
if instance:IsA("ScreenGui") and not instance:GetAttribute("ShowInPhotoBooth") and instance.Enabled then
instance.Enabled = false
table.insert(hiddenInstances, instance)
end
end
-- 隱藏特定的核心 GUI
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
end)
PhotoBooth.showOtherGuis(function()
-- 顯示所有被隱藏的開發者定義的屏幕 GUI
for _, instance in hiddenInstances do
instance.Enabled = true
end
hiddenInstances = {}
-- 顯示被隱藏的特定核心 GUI
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end)
API 參考
函數
configure
configure(config: table)
通過 config 表中的以下鍵/值覆蓋默認配置選項。此函數只能從 LocalScript 中調用。
| 鍵 | 描述 | 默認值 |
|---|---|---|
| frameMessage | 顯示在照片底部的消息。其持續時間可以通過 fadeUiDelay 屬性控制。 | "使用您的設備拍攝截圖並分享!" |
| fadeUiDelay | 在淡出之前顯示框架消息的時間(以秒為單位)。設置為負數以防止淡出。 | 3 |
| closeButtonImage | 用作關閉照片按鈕的圖像,放置在 closeButtonBackgroundImage 圖像的上方。 | "rbxassetid://7027440823" |
| closeButtonBackgroundImage | 用於關閉照片按鈕的背景圖像。 | "rbxassetid://7027440891" |
| cameraLandscapePosition | 在橫屏模式下拍攝照片時,照相亭鏡頭在角色前方和上方的距離(Vector2)。 | (5, 2) |
| cameraPortraitPosition | 在竖屏模式下拍攝照片時,照相亭鏡頭在角色前方和上方的距離(Vector2)。 | (10, 1) |
| countdownFont | 用於倒計時中的數字的字型(Enum.Font)。 | GothamBlack |
| countdownTextColor | 倒計時中數字的顏色(Color3)。 | [255, 255, 255] |
| printoutCharacterPosition | 打印件顯示時角色在屏幕上的位置(UDim2)。 | (0.5, 0, 0.5, 0) |
| printoutCharacterSize | 角色在打印件中佔用的屏幕空間(UDim2)。 | (1, 0, 1, 0) |
| characterAnimation | 角色在照片中採取的動畫的資產 ID,暫停在其起始幀。 | "rbxassetid://6899663224" |
| filterImage | 要應用於照片的過濾器圖像。如果為 nil,則將使用默認過濾器來暗化圖像邊緣。 | nil |
LocalScript - ConfigurePhotoBoothlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local PhotoBooth = require(ReplicatedStorage.PhotoBooth)PhotoBooth.configure({frameMessage = "多酷的姿勢!",fadeUiDelay = 5,maxActivationDistance = 5,printoutCharacterSize = UDim2.fromScale(1.5, 1.5),})
setBackgrounds
setBackgrounds(backgrounds: table)
覆蓋照相亭提供的默認背景。背景圖像應以 16:9 的寬高比(1024×576)來獲得最佳體驗,並且其資產 ID 應包含在背景數組中。可以提供 1–4 (包含)個背景。
LocalScriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local PhotoBooth = require(ReplicatedStorage.PhotoBooth)PhotoBooth.setBackgrounds({"rbxassetid://7018713114","rbxassetid://950538356",})
事件
countdownStarted
當倒計時開始時觸發。此事件只能在 LocalScript 中連接。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhotoBooth = require(ReplicatedStorage.PhotoBooth)
PhotoBooth.countdownStarted:Connect(function()
print("倒計時已開始")
end)
printoutShown
當打印件顯示給用戶時觸發。此事件只能在 LocalScript 中連接。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhotoBooth = require(ReplicatedStorage.PhotoBooth)
PhotoBooth.printoutShown:Connect(function()
print("打印件顯示中")
end)
promptShown
當打印件關閉且攝像頭按鈕再次顯示時觸發。此事件只能在 LocalScript 中連接。
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhotoBooth = require(ReplicatedStorage.PhotoBooth)
PhotoBooth.promptShown:Connect(function()
print("攝像頭提示顯示中")
end)
回調
hideOtherGuis
hideOtherGuis(callback: function)
此回調在打印件顯示之前立即執行,讓您在打印件顯示之前禁用整個 ScreenGuis 或其中的元素。照相亭使用的 GUI 具有屬性 ShowInPhotoBooth 設置為 true。詳細信息及示例代碼請參見 GUI 可見性。
showOtherGuis
showOtherGuis(callback: function)
此回調在打印件關閉後執行,讓您重新啟用整個 ScreenGuis 或其中的元素。照相亭使用的 GUI 具有屬性 ShowInPhotoBooth 設置為 true。詳細信息及示例代碼請參見 GUI 可見性。