Engine Class
ContentProvider
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
คุณสมบัติ
วิธีการ
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
ตัวอย่างโค้ด
แถบโหลด 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
-- สร้างแถบโหลดพื้นฐาน
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 |
ส่งค่ากลับ
ตัวอย่างโค้ด
ตรวจสอบสถานะ AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- ตัวอย่าง Asset ที่จะโหลด
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- แสดงสถานะ AssetFetchStatus ปัจจุบันของ Asset
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)
-- เรียก Asset ให้โหลดล่วงหน้า
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`สถานะการโหลดล่วงหน้า {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)GetAssetFetchStatusChangedSignal
พารามิเตอร์
contentId:ContentId |
ส่งค่ากลับ
ตัวอย่างโค้ด
ตรวจสอบสถานะ AssetFetchStatus
local ContentProvider = game:GetService("ContentProvider")
-- ตัวอย่าง Asset ที่จะโหลด
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- แสดงสถานะ AssetFetchStatus ปัจจุบันของ Asset
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)
-- เรียก Asset ให้โหลดล่วงหน้า
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() แก้ไข Asset ID:", assetId)
print("PreloadAsync() สถานะการดึง Asset สุดท้าย:", 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