Engine-klasse
ContentProvider
*Deze inhoud is vertaald met behulp van AI (bèta) en kan fouten bevatten. Klik hier om deze pagina in het Engels te bekijken.
Samenvatting
Eigenschappen
Methoden
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):() |
Evenementen
AssetFetchFailed(assetId: ContentId):RBXScriptSignal |
Codevoorbeelden
InhoudProvider
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("Alle assets zijn geladen.")API-referentie
Eigenschappen
RequestQueueSize
Codevoorbeelden
InhoudProvider Laadbalk
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
-- maak een basis laadbalk
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 tegelijk, yield
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end
print("laden voltooid")Methoden
GetAssetFetchStatus
Parameters
contentId:ContentId |
Teruggaves
Codevoorbeelden
Monitoring AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- Een voorbeeld asset om te laden
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Geef de huidige AssetFetchStatus van de asset weer
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Initiële AssetFetchStatus:", initialAssetFetchStatus)
-- Luister naar updates
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Nieuwe AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Trigger de asset om voor te laden
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Voorlaadstatus {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)GetAssetFetchStatusChangedSignal
Parameters
contentId:ContentId |
Teruggaves
Codevoorbeelden
Monitoring AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- Een voorbeeld asset om te laden
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Geef de huidige AssetFetchStatus van de asset weer
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Initiële AssetFetchStatus:", initialAssetFetchStatus)
-- Luister naar updates
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Nieuwe AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Trigger de asset om voor te laden
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Voorlaadstatus {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)Preload
PreloadAsync
Teruggaves
()
Codevoorbeelden
Vooraf laden van middelen
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,
}
-- Dit zal worden aangeroepen wanneer elk middel is opgelost
local callback = function(assetId, assetFetchStatus)
print("PreloadAsync() heeft middel ID opgelost:", assetId)
print("PreloadAsync() eindstatus van AssetFetchStatus:", assetFetchStatus)
end
-- Laad de inhoud vooraf en meet de tijd
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("Vooraf laden voltooid, duurde %.2f seconden"):format(deltaTime))RegisterDefaultEncryptionKey
RegisterDefaultSessionKey
RegisterEncryptedAsset
RegisterSessionEncryptedAsset
UnregisterDefaultEncryptionKey
ContentProvider:UnregisterDefaultEncryptionKey():()
Teruggaves
()
UnregisterEncryptedAsset
ContentProvider:UnregisterEncryptedAsset(assetId:ContentId):()
Parameters
assetId:ContentId |
Teruggaves
()
Evenementen
AssetFetchFailed