Content Provider
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm tắt
Thuộc Tính
Phương Pháp
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):() |
Sự Kiện
AssetFetchFailed(assetId: ContentId):RBXScriptSignal |
Mẫu mã
Trình cung cấp nội dung
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("Tất cả tài sản đã được tải.")Tài Liệu Tham Khảo API
Thuộc Tính
Request Queue Size
Mẫu mã
Thanh Tải Nội Dung
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
-- tạo một thanh tải cơ bản
local frame = Instance.new("Frame")
frame.Size = UDim2.fromScale(0.5, 0.1)
frame.Position = UDim2.fromScale(0.5, 0.5)
frame.AnchorPoint = Vector2.new(0.5, 0.5)
frame.Parent = screenGui
local bar = Instance.new("Frame")
bar.Size = UDim2.fromScale(0, 1)
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 cái một, sẽ tạm dừng
local progress = i / #assets
bar.Size = UDim2.fromScale(progress, 1)
end
print("tải xong")Phương Pháp
Get Asset Fetch Status
Tham Số
contentId:ContentId |
Lợi Nhuận
Mẫu mã
Giám sát trạng thái AssetFetch
local ContentProvider = game:GetService("ContentProvider")
-- Một tài sản ví dụ để tải
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Xuất trạng thái AssetFetchStatus hiện tại của tài sản
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Trạng thái AssetFetchStatus ban đầu:", initialAssetFetchStatus)
-- Lắng nghe các cập nhật
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Trạng thái AssetFetchStatus mới: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Kích hoạt tài sản để nạp trước
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Trạng thái nạp trước {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)Get Asset Fetch Status Changed Signal
Tham Số
contentId:ContentId |
Lợi Nhuận
Mẫu mã
Giám sát trạng thái AssetFetch
local ContentProvider = game:GetService("ContentProvider")
-- Một tài sản ví dụ để tải
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Xuất trạng thái AssetFetchStatus hiện tại của tài sản
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Trạng thái AssetFetchStatus ban đầu:", initialAssetFetchStatus)
-- Lắng nghe các cập nhật
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`Trạng thái AssetFetchStatus mới: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Kích hoạt tài sản để nạp trước
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Trạng thái nạp trước {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)Preload
Preload Async
Lợi Nhuận
()
Mẫu mã
Tải trước Tài sản
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,
}
-- Điều này sẽ được thực hiện khi mỗi tài sản được giải quyết
local callback = function(assetId, assetFetchStatus)
print("PreloadAsync() đã giải quyết ID tài sản:", assetId)
print("PreloadAsync() trạng thái cuối cùng của AssetFetchStatus:", assetFetchStatus)
end
-- Tải trước nội dung và tính thời gian
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("Tải trước hoàn tất, mất %.2f giây"):format(deltaTime))Register Default Encryption Key
Register Default Session Key
Register Encrypted Asset
Register Session Encrypted Asset
Unregister Default Encryption Key
Content Provider: Unregister Default Encryption Key():()
Lợi Nhuận
()
Unregister Encrypted Asset
Content Provider: Unregister Encrypted Asset(asset Id:ContentId):()
Tham Số
assetId:ContentId |
Lợi Nhuận
()
Sự Kiện
Asset Fetch Failed