Impara
Classe motore
ContentProvider
Non costruibile
Assistenza
Non Replicato

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.


Sommario
Metodi
Preload(contentId: ContentId):()
Obsoleto
PreloadAsync(contentIdList: {any},callbackFunction: function):()
RegisterEncryptedAsset(assetId: ContentId,encryptionKey: string):()
RegisterSessionEncryptedAsset(contentId: ContentId,sessionKey: string):()
UnregisterEncryptedAsset(assetId: ContentId):()
Eventi
AssetFetchFailed(assetId: ContentId):RBXScriptSignal
Membri ereditati
Campioni di codice
ContentProvider
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("Tutti gli asset sono stati caricati.")

Riferimento API
Proprietà
BaseUrl
Sola Lettura
Non Replicato
Lettura Parallela
Capacità: AssetManagement
ContentProvider.BaseUrl:string

RequestQueueSize
Sola Lettura
Non Replicato
Lettura Parallela
Capacità: AssetManagement
ContentProvider.RequestQueueSize:number
Campioni di codice
Barra di Caricamento 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
-- crea una barra di caricamento di base
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 alla volta, sospende
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end
print("caricamento completato")

Metodi
GetAssetFetchStatus
Capacità: AssetManagement
ContentProvider:GetAssetFetchStatus(contentId:ContentId):Enum.AssetFetchStatus
Parametri
contentId:ContentId
Campioni di codice
Monitoraggio AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- Un esempio di asset da caricare
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Visualizza l'AssetFetchStatus attuale dell'asset
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("AssetFetchStatus iniziale:", initialAssetFetchStatus)
-- Ascolta gli aggiornamenti
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Nuovo AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Attiva il caricamento netto dell'asset
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Stato del preload {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)

GetAssetFetchStatusChangedSignal
Capacità: AssetManagement
ContentProvider:GetAssetFetchStatusChangedSignal(contentId:ContentId):RBXScriptSignal
Parametri
contentId:ContentId
Restituzioni
Campioni di codice
Monitoraggio AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- Un esempio di asset da caricare
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Visualizza l'AssetFetchStatus attuale dell'asset
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("AssetFetchStatus iniziale:", initialAssetFetchStatus)
-- Ascolta gli aggiornamenti
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Nuovo AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Attiva il caricamento netto dell'asset
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Stato del preload {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)

ListEncryptedAssets
Capacità: AssetManagement
ContentProvider:ListEncryptedAssets():{any}
Restituzioni

Preload
Obsoleto

PreloadAsync
Resa
Capacità: AssetManagement
ContentProvider:PreloadAsync(
contentIdList:{any}, callbackFunction:function
):()
Parametri
contentIdList:{any}
callbackFunction:function
Valore predefinito: "nil"
Restituzioni
()
Campioni di codice
Precaricamento Risorse
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,
}
-- Questo verrà colpito man mano che ogni risorsa si risolve
local callback = function(assetId, assetFetchStatus)
print("PreloadAsync() ha risolto l'ID asset:", assetId)
print("PreloadAsync() stato finale di AssetFetchStatus:", assetFetchStatus)
end
-- Precarica il contenuto e cronometralo
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("Precaricamento completo, ci sono voluti %.2f secondi"):format(deltaTime))

RegisterDefaultEncryptionKey
Capacità: AssetManagement
ContentProvider:RegisterDefaultEncryptionKey(encryptionKey:string):()
Parametri
encryptionKey:string
Restituzioni
()

RegisterDefaultSessionKey
Capacità: AssetManagement
ContentProvider:RegisterDefaultSessionKey(sessionKey:string):()
Parametri
sessionKey:string
Restituzioni
()

RegisterEncryptedAsset
Capacità: AssetManagement
ContentProvider:RegisterEncryptedAsset(
assetId:ContentId, encryptionKey:string
):()
Parametri
assetId:ContentId
encryptionKey:string
Restituzioni
()

RegisterSessionEncryptedAsset
Capacità: AssetManagement
ContentProvider:RegisterSessionEncryptedAsset(
contentId:ContentId, sessionKey:string
):()
Parametri
contentId:ContentId
sessionKey:string
Restituzioni
()

UnregisterDefaultEncryptionKey
Capacità: AssetManagement
ContentProvider:UnregisterDefaultEncryptionKey():()
Restituzioni
()

UnregisterEncryptedAsset
Capacità: AssetManagement
ContentProvider:UnregisterEncryptedAsset(assetId:ContentId):()
Parametri
assetId:ContentId
Restituzioni
()

Eventi
AssetFetchFailed
Capacità: AssetManagement
ContentProvider.AssetFetchFailed(assetId:ContentId):RBXScriptSignal
Parametri
assetId:ContentId

© 2026 Roblox Corporation. Roblox, il logo Roblox e Powering Imagination sono tra i nostri marchi registrati e non registrati negli Stati Uniti. e altri paesi.