콘텐츠(자산)를 게임에 로드하는 서비스.
Roblox 서버는 런타임에 모든 자산을 클라이언트에 스트리밍합니다: 작업 공간의 개체, 메쉬 자산, 텍스처 자산 등.메쉬 시각 데이터, 텍스처, 데칼, 사운드와 같은 자산은 스트리밍이 활성화되었는지 여부에 관계없이 필요한 대로 스트리밍됩니다.
경우에 따라 콘텐츠가 경험에 로드되기 전에 지연이 발생할 수 있으므로 이 동작은 바람직하지 않습니다.
ContentProvider 방법을 사용하여 경험에 자산을 미리 로드할 수 있습니다. ContentProvider:PreloadAsync()로딩 화면을 표시하고, 중요한 자산을 미리 로드하고, 플레이어가 경험에 들어올 수 있도록 허용하는 것이 좋습니다.
사전 로드에 대한 모범 사례
- 필수 자산만 미리 로드하고, 아님 전체 Workspace를 로드하지 않습니다.가끔 팝업이 표시될 수 있지만 로드 시간이 줄어들고 일반적으로 플레이어 경험을 방해하지 않습니다.미리 로드할 수 있는 좋은 후보 자산에는 로딩 화면, UI 또는 시작 영역에 필요한 자산이 포함됩니다.
- 플레이어가 로딩 화면을 건너뛰거나 일정 시간 후에 자동으로 건너뛰도록 합니다.
코드 샘플
local ContentProvider = game:GetService("ContentProvider")
local LOGO_ID = "rbxassetid://658743164"
local PAGE_TURN_ID = "rbxassetid://12222076"
local decal = Instance.new("Decal")
decal.Texture = LOGO_ID
local sound = Instance.new("Sound")
sound.SoundId = PAGE_TURN_ID
local assets = { decal, sound }
ContentProvider:PreloadAsync(assets)
print("All assets loaded.")
요약
속성
ContentProvider에서 Roblox 웹사이트에서 자산을 다운로드하기 위해 사용됩니다.
다운로드해야 하는 ContentProvider 요청 큐열의 아이템 수를 제공합니다.
메서드
제공된 Enum.AssetFetchStatus의 현재 contentId를 가져옵니다.
제공된 콘텐츠의 Enum.AssetFetchStatus가 변경될 때 발생하는 신호.
지정된 Instances와 관련된 모든 자산이 로드될 때까지 생성됩니다.
이벤트
속성
BaseUrl
ContentProvider에서 Roblox 웹사이트에서 자산을 다운로드하기 위해 사용됩니다.
이 URL은 버전 해시 폴더에 있는 AppSettings.xml 파일에서 자산을 다운로드하고 가져오는 Roblox 호스팅 웹사이트로 가리킵니다.
명령 줄의 ContentProvider:SetBaseUrl() 함수를 사용하여 이 속성을 덮어쓸 수 있지만, 권장되지 않으며 자산 로드 문제를 일으킬 수 있습니다.
RequestQueueSize
다운로드해야 하는 ContentProvider 요청 큐열의 아이템 수를 제공합니다.
자산이 처음 사용되거나 ContentProvider:PreloadAsync()가 호출될 때 항목이 클라이언트의 요청 큐에 추가됩니다.
개발자는 요청 대기 시간 크기를 사용하여 로딩 바를 생성하지 않는 것이 좋습니다.이는 새로운 자산이 추가되고 다운로드될 때 대기 크기가 증가하고 감소할 수 있기 때문입니다.로딩 진행률을 표시하려는 개발자는 한 번에 자산을 하나씩 로드해야 합니다(아래 예제 참조).
코드 샘플
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
-- create a basic loading bar
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 at a time, yields
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end
print("loading done")
메서드
GetAssetFetchStatus
제공된 의 현재 값을 가져옵니다. 이 값에 대한 변경을 감지하려면 를 사용하십시오.
매개 변수
상태를 가져올 콘텐츠의 ID.
반환
코드 샘플
local ContentProvider = game:GetService("ContentProvider")
-- An example asset to load
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Output the current AssetFetchStatus of the asset
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Initial AssetFetchStatus:", initialAssetFetchStatus)
-- Listen for updates
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`New AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Trigger the asset to preload
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Preload status {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)
GetAssetFetchStatusChangedSignal
제공된 콘텐츠의 Enum.AssetFetchStatus가 변경될 때 발생하는 신호.호출백을 사용하여 형식 Enum.AssetFetchStatus 의 하나의 인수로 이 신호에 연결합니다.이는 사용자가 옷을 바꿀 때 사용자의 썸네일처럼 자동으로 업데이트될 수 있는 자산에 특히 유용합니다.
매개 변수
반환
코드 샘플
local ContentProvider = game:GetService("ContentProvider")
-- An example asset to load
local ASSET_ID = "rbxassetid://9120386436"
local exampleAsset = Instance.new("Sound")
exampleAsset.SoundId = ASSET_ID
-- Output the current AssetFetchStatus of the asset
local initialAssetFetchStatus = ContentProvider:GetAssetFetchStatus(ASSET_ID)
print("Initial AssetFetchStatus:", initialAssetFetchStatus)
-- Listen for updates
local assetFetchStatusChangedSignal = ContentProvider:GetAssetFetchStatusChangedSignal(ASSET_ID)
local function onAssetFetchStatusChanged(newAssetFetchStatus: Enum.AssetFetchStatus)
print(`New AssetFetchStatus: {newAssetFetchStatus}`)
end
assetFetchStatusChangedSignal:Connect(onAssetFetchStatusChanged)
-- Trigger the asset to preload
local function onAssetRequestComplete(contentId: string, assetFetchStatus: Enum.AssetFetchStatus)
print(`Preload status {contentId}: {assetFetchStatus.Name}`)
end
ContentProvider:PreloadAsync({ exampleAsset }, onAssetRequestComplete)
UnregisterDefaultEncryptionKey
반환
UnregisterEncryptedAsset
매개 변수
반환
PreloadAsync
지정된 Instances와 관련된 모든 자산이 로드될 때까지 생성됩니다.스크립트를 일시 중지하고 콘텐츠가 경험에 로드되었는지 확인될 때까지 콘텐츠를 사용하지 않을 수 있습니다.
호출되면 엔진은 목록의 각 항목에 대한 콘텐츠 링크를 식별합니다.콘텐츠에 대한 링크를 정의하는 속성을 가진 모든 Instances에 대해 엔진은 Roblox에서 이러한 자산을 로드하려고 시도합니다.For any of the which have properties that define links to content, such as a Decal or a Sound , the engine attempts to load these assets from Roblox.요청된 각 자산에 대해 콜백 함수가 실행되어 자산의 최종 Enum.AssetFetchStatus 을 나타냅니다.
자산 중 하나라도 불러오다않으면 출력에 오류 메시지가 나타납니다.메서드 자체는 오류가 발생하지 않으며 요청된 각 인스턴스를 처리할 때까지 계속 실행됩니다.
제한
SurfaceAppearance 및 MaterialVariant 는 개별 텍스처를 직접 로드하는 대신 처리된 텍스처 팩 자산에 의존하기 때문에 PreloadAsync() 에서 지원되지 않습니다.그것을 SurfaceAppearance 인스턴스에서 호출하면 아무것도 수행되지 않지만 연결된 텍스처는 런타임 중에 여전히 스트리밍됩니다.
매개 변수
로드할 인스턴스 불러오다.
각 자산 요청이 완료될 때 호출되는 함수. content 문자열과 자산의 최종 Enum.AssetFetchStatus를 반환합니다.
반환
코드 샘플
local ContentProvider = game:GetService("ContentProvider")
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
local decal = Instance.new("Decal")
decal.Texture = "rbxassetid://5447528495"
local assets = {
decal,
sound,
}
-- This will be hit as each asset resolves
local callback = function(assetId, assetFetchStatus)
print("PreloadAsync() resolved asset ID:", assetId)
print("PreloadAsync() final AssetFetchStatus:", assetFetchStatus)
end
-- Preload the content and time it
local startTime = os.clock()
ContentProvider:PreloadAsync(assets, callback)
local deltaTime = os.clock() - startTime
print(("Preloading complete, took %.2f seconds"):format(deltaTime))