學習
引擎類別
ContentProvider
無法建立
服務
未複製

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


概要
方法
Preload(contentId: ContentId):()
已棄用
PreloadAsync(contentIdList: {any},callbackFunction: function):()
RegisterEncryptedAsset(assetId: ContentId,encryptionKey: string):()
RegisterSessionEncryptedAsset(contentId: ContentId,sessionKey: string):()
UnregisterEncryptedAsset(assetId: ContentId):()
活動
AssetFetchFailed(assetId: ContentId):RBXScriptSignal
繼承成員
範例程式碼
內容提供器
local ContentProvider = game:GetService("ContentProvider")
local LOGO_ID = "rbxassetid://658743164"
local PAGE_TURN_ID = "rbxassetid://12222076"
local decal = Instance.new("Decal")
decal.ColorMapContent = Content.fromUri(LOGO_ID)
local sound = Instance.new("Sound")
sound.SoundId = PAGE_TURN_ID
local assets = { decal, sound }
ContentProvider:PreloadAsync(assets)
print("所有資產已加載。")

API 參考
屬性
BaseUrl
唯讀
未複製
平行讀取
功能: AssetManagement
ContentProvider.BaseUrl:string

RequestQueueSize
唯讀
未複製
平行讀取
功能: AssetManagement
ContentProvider.RequestQueueSize:number
範例程式碼
內容提供者加載條
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- 創建一個基本的加載條
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0.5, 0, 0.1, 0)
frame.Position = UDim2.new(0.5, 0, 0.5, 0)
frame.AnchorPoint = Vector2.new(0.5, 0.5)
frame.Parent = screenGui
local bar = Instance.new("Frame")
bar.Size = UDim2.new(0, 0, 1, 0)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.BackgroundColor3 = Color3.new(0, 0, 1)
bar.Parent = frame
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
local sound2 = Instance.new("Sound")
sound2.SoundId = "rbxassetid://9120385974"
local assets = {
sound,
sound2,
}
task.wait(3)
for i = 1, #assets do
local asset = assets[i]
ContentProvider:PreloadAsync({ asset }) -- 一次一個,會暫停
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end
print("加載完成")

方法
GetAssetFetchStatus
功能: AssetManagement
ContentProvider:GetAssetFetchStatus(contentId:ContentId):Enum.AssetFetchStatus
參數
contentId:ContentId
範例程式碼
監控資產獲取狀態
local ContentProvider = game:GetService("ContentProvider")
-- 一個示例 資產來加載
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- 輸出 資產當前的 AssetFetchStatus
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("初始 AssetFetchStatus:", initialAssetFetchStatus)
-- 監聽 更新
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`新的 AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- 觸發資產預加載
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`預加載狀態 {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)

GetAssetFetchStatusChangedSignal
功能: AssetManagement
ContentProvider:GetAssetFetchStatusChangedSignal(contentId:ContentId):RBXScriptSignal
參數
contentId:ContentId
範例程式碼
監控資產獲取狀態
local ContentProvider = game:GetService("ContentProvider")
-- 一個示例 資產來加載
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- 輸出 資產當前的 AssetFetchStatus
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("初始 AssetFetchStatus:", initialAssetFetchStatus)
-- 監聽 更新
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`新的 AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- 觸發資產預加載
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`預加載狀態 {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)

ListEncryptedAssets
功能: AssetManagement
ContentProvider:ListEncryptedAssets():{any}
返回

Preload
已棄用

PreloadAsync
暫停
功能: AssetManagement
ContentProvider:PreloadAsync(
contentIdList:{any}, callbackFunction:function
):()
參數
contentIdList:{any}
callbackFunction:function
預設值:"nil"
返回
()
範例程式碼
預加載資源
local ContentProvider = game:GetService("ContentProvider")
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
local decal = Instance.new("Decal")
decal.ColorMapContent = Content.fromUri("rbxassetid://5447528495")
local assets = {
decal,
sound,
}
-- 每當資產解析時將被觸發
local callback = function(assetId, assetFetchStatus)
print("PreloadAsync() 解析的資產 ID:", assetId)
print("PreloadAsync() 最終的 AssetFetchStatus:", assetFetchStatus)
end
-- 預加載內容並計時
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("預加載完成,耗時 %.2f 秒"):format(deltaTime))

RegisterDefaultEncryptionKey
功能: AssetManagement
ContentProvider:RegisterDefaultEncryptionKey(encryptionKey:string):()
參數
encryptionKey:string
返回
()

RegisterDefaultSessionKey
功能: AssetManagement
ContentProvider:RegisterDefaultSessionKey(sessionKey:string):()
參數
sessionKey:string
返回
()

RegisterEncryptedAsset
功能: AssetManagement
ContentProvider:RegisterEncryptedAsset(
assetId:ContentId, encryptionKey:string
):()
參數
assetId:ContentId
encryptionKey:string
返回
()

RegisterSessionEncryptedAsset
功能: AssetManagement
ContentProvider:RegisterSessionEncryptedAsset(
contentId:ContentId, sessionKey:string
):()
參數
contentId:ContentId
sessionKey:string
返回
()

UnregisterDefaultEncryptionKey
功能: AssetManagement
ContentProvider:UnregisterDefaultEncryptionKey():()
返回
()

UnregisterEncryptedAsset
功能: AssetManagement
ContentProvider:UnregisterEncryptedAsset(assetId:ContentId):()
參數
assetId:ContentId
返回
()

活動
AssetFetchFailed
功能: AssetManagement
ContentProvider.AssetFetchFailed(assetId:ContentId):RBXScriptSignal
參數
assetId:ContentId

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。