Classe do mecanismo
ContentProvider
*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.
Resumo
Propriedades
Métodos
GetAssetFetchStatus(contentId: ContentId):Enum.AssetFetchStatus |
GetAssetFetchStatusChangedSignal(contentId: ContentId):RBXScriptSignal |
Preload(contentId: ContentId):() |
PreloadAsync(contentIdList: {any},callbackFunction: function):() |
RegisterDefaultEncryptionKey(encryptionKey: string):() |
RegisterDefaultSessionKey(sessionKey: string):() |
RegisterEncryptedAsset(assetId: ContentId,encryptionKey: string):() |
RegisterSessionEncryptedAsset(contentId: ContentId,sessionKey: string):() |
UnregisterEncryptedAsset(assetId: ContentId):() |
Eventos
AssetFetchFailed(assetId: ContentId):RBXScriptSignal |
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
RequestQueueSize
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
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)GetAssetFetchStatusChangedSignal
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)Preload
PreloadAsync
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
RegisterDefaultSessionKey
RegisterEncryptedAsset
RegisterSessionEncryptedAsset
UnregisterDefaultEncryptionKey
ContentProvider:UnregisterDefaultEncryptionKey():()
Devolução
()
UnregisterEncryptedAsset
ContentProvider:UnregisterEncryptedAsset(assetId:ContentId):()
Parâmetros
assetId:ContentId |
Devolução
()
Eventos
AssetFetchFailed