エンジンクラス
ContentProvider
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
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):() |
イベント
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リファレンス
プロパティ
RequestQueueSize
コードサンプル
コンテンツプロバイダーのロードバー
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 }) -- 1つずつ、待機します
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end
print("ローディング完了")方法
GetAssetFetchStatus
パラメータ
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
パラメータ
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)Preload
PreloadAsync
戻り値
()
コードサンプル
アセットのプリロード
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)
end
-- コンテンツをプリロードし、その時間を計測します
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("プリロード完了、所要時間 %.2f 秒"):format(deltaTime))RegisterDefaultEncryptionKey
RegisterDefaultSessionKey
RegisterEncryptedAsset
RegisterSessionEncryptedAsset
UnregisterDefaultEncryptionKey
ContentProvider:UnregisterDefaultEncryptionKey():()
戻り値
()
UnregisterEncryptedAsset
ContentProvider:UnregisterEncryptedAsset(assetId:ContentId):()
パラメータ
assetId:ContentId |
戻り値
()
イベント
AssetFetchFailed