Aprenda
Classe do mecanismo
ContentProvider
Não criável
Serviço
Não replicado

*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.


Resumo
Métodos
Preload(contentId: ContentId):()
Obsoleto
PreloadAsync(contentIdList: {any},callbackFunction: function):()
RegisterEncryptedAsset(assetId: ContentId,encryptionKey: string):()
RegisterSessionEncryptedAsset(contentId: ContentId,sessionKey: string):()
UnregisterEncryptedAsset(assetId: ContentId):()
Eventos
AssetFetchFailed(assetId: ContentId):RBXScriptSignal
Membros herdados
Amostras de código
ProvedorDeConteúdo
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("Todos os ativos carregados.")

Referência API
Propriedades
BaseUrl
Somente leitura
Não replicado
Ler Parallel
Recursos: AssetManagement
ContentProvider.BaseUrl:string

RequestQueueSize
Somente leitura
Não replicado
Ler Parallel
Recursos: AssetManagement
ContentProvider.RequestQueueSize:number
Amostras de código
Barra de Carregamento do ContentProvider
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
-- cria uma barra de carregamento básica
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 }) -- 1 por vez, suspende
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end
print("carregamento concluído")

Métodos
GetAssetFetchStatus
Recursos: AssetManagement
ContentProvider:GetAssetFetchStatus(contentId:ContentId):Enum.AssetFetchStatus
Parâmetros
contentId:ContentId
Amostras de código
Monitorando AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- Um exemplo de ativo para carregar
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Saída do estado atual de AssetFetchStatus do ativo
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Estado inicial de AssetFetchStatus:", initialAssetFetchStatus)
-- Ouvir por atualizações
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Novo AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Acionar o pré-carregamento do ativo
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Status de pré-carregamento {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)

GetAssetFetchStatusChangedSignal
Recursos: AssetManagement
ContentProvider:GetAssetFetchStatusChangedSignal(contentId:ContentId):RBXScriptSignal
Parâmetros
contentId:ContentId
Devolução
Amostras de código
Monitorando AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- Um exemplo de ativo para carregar
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Saída do estado atual de AssetFetchStatus do ativo
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Estado inicial de AssetFetchStatus:", initialAssetFetchStatus)
-- Ouvir por atualizações
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Novo AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Acionar o pré-carregamento do ativo
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Status de pré-carregamento {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)

ListEncryptedAssets
Recursos: AssetManagement
ContentProvider:ListEncryptedAssets():{any}
Devolução

Preload
Obsoleto

PreloadAsync
Rendimentos
Recursos: AssetManagement
ContentProvider:PreloadAsync(
contentIdList:{any}, callbackFunction:function
):()
Parâmetros
contentIdList:{any}
callbackFunction:function
Valor Padrão: "nil"
Devolução
()
Amostras de código
Pré-carregando Ativos
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,
}
-- Isso será executado à medida que cada ativo for resolvido
local callback = function(assetId, assetFetchStatus)
print("PreloadAsync() resolveu o ID do ativo:", assetId)
print("PreloadAsync() Status final do AssetFetch:", assetFetchStatus)
end
-- Pré-carregue o conteúdo e meça o tempo
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("Pré-carregamento completo, levou %.2f segundos"):format(deltaTime))

RegisterDefaultEncryptionKey
Recursos: AssetManagement
ContentProvider:RegisterDefaultEncryptionKey(encryptionKey:string):()
Parâmetros
encryptionKey:string
Devolução
()

RegisterDefaultSessionKey
Recursos: AssetManagement
ContentProvider:RegisterDefaultSessionKey(sessionKey:string):()
Parâmetros
sessionKey:string
Devolução
()

RegisterEncryptedAsset
Recursos: AssetManagement
ContentProvider:RegisterEncryptedAsset(
assetId:ContentId, encryptionKey:string
):()
Parâmetros
assetId:ContentId
encryptionKey:string
Devolução
()

RegisterSessionEncryptedAsset
Recursos: AssetManagement
ContentProvider:RegisterSessionEncryptedAsset(
contentId:ContentId, sessionKey:string
):()
Parâmetros
contentId:ContentId
sessionKey:string
Devolução
()

UnregisterDefaultEncryptionKey
Recursos: AssetManagement
ContentProvider:UnregisterDefaultEncryptionKey():()
Devolução
()

UnregisterEncryptedAsset
Recursos: AssetManagement
ContentProvider:UnregisterEncryptedAsset(assetId:ContentId):()
Parâmetros
assetId:ContentId
Devolução
()

Eventos
AssetFetchFailed
Recursos: AssetManagement
ContentProvider.AssetFetchFailed(assetId:ContentId):RBXScriptSignal
Parâmetros
assetId:ContentId

©2026 Roblox Corporation, Roblox, o logotipo Roblox e Powering Imagination estão entre nossas marcas registradas e não registradas nos EUA e em outros países.