본문 바로가기
API 문서

ContentProvider

by Roblox_개발자 2021. 4. 10.

ContentProvider는 content나 asset을 게임에 로드 하기위해 사용되는 서비스다.

주된 사용은 asset들을 게임에 preload 하는 것이다. 새로운 asset이 사용될 때, 로블록스는 서버로부터 그것과 관련이 있는 content를 로드하게 된다. 일부의 경우에, content를 preload하는 것이 게임에 딜레이를 발생시키기 때문에 개발자들에게 꺼려질 수 있다. 

ContentProvider:PreloadAsync 함수를 사용해서 서버에 있는 assets을 불러올 수 있다. 다른 유용한 속성은ContentProvider.RequestQueueSize인데, 이것은 요청 대기열에서 다운로드 된 assets의 비율을 측정하는 데 사용할 수 있다. (로딩바 만들때 사용하면 될 듯)

 

[PreloadAsync]

Parameter

  • contentIdList - preload될 인스턴스들에 대한 배열
  • callbackFunction - 각 asset의 요청이 완료될 때마다 실행되는 콜백함수(asset이 3개면 3번 실행

Return

리턴값은 없음

 

Preloading Assets 예제

local ContentProvider = game:GetService("ContentProvider")
 
local waitingImage = "rbxassetid://1234561"
 
local thumbLeft = "rbxthumb://type=Avatar&id=1234&w=100&h=100"
local thumbRight = "rbxthumb://type=Avatar&id=1235&w=100&h=100"
 
local failedImageLeft = "rbxassetid://1234562"
local failedImageRight = "rbxassetid://1234563"
 
local labelLeft = script.Parent.LabelLeft
labelLeft.Image = waitingImage
 
local labelRight = script.Parent.LabelRight
labelRight.Image = waitingImage
 
local assets = { thumbLeft, thumbRight }
 
local function setThumb(contentId, status)
	if thumbLeft == contentId then
		labelLeft.Image = Enum.AssetFetchStatus.Success == status and thumbLeft or failedImageLeft
	elseif thumbRight == contentId then
		labelRight.Image = Enum.AssetFetchStatus.Success == status and thumbRight or failedImageRight
	end
end
 
spawn(function()
	ContentProvider:PreloadAsync(assets, setThumb)
end)

 

[RequestQueueSize]

RequestQueueSize는 다운로드를 기다리고 있는 ContentProvider의 요청 대기열에있는 항목 수를 제공한다.

asset이 처음으로 사용되거나 ContentProvider:PreloadAsync가 호출되면 항목이 클라이언트의 요청 대기열에 추가된다. 개발자는 로딩 바를 생성하기 위해 RequestQueueSize를 사용하지 않는 것이 좋다.

이는 새 asset이 추가 및 다운로드됨에 따라 대기열 크기가 시간이 지남에 따라 증가 및 감소 할 수 있기 때문이다. 로딩바를 표시하려는 개발자는 한 번에 하나씩 asset을 로드해야 한다 (아래 예제 참조).

 

Code Samples - ContentProvider Loading Bar

local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
 
-- create a screenGui
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui", playerGui)
 
-- create a basic loading bar
local frame = Instance.new("Frame", screenGui)
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)
 
local bar = Instance.new("Frame", frame)
bar.Size = UDim2.new(0, 0, 1, 0)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.BackgroundColor3 = Color3.new(0, 0, 1)
 
-- create some sample assets
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://301964312"
local sound2 = Instance.new("Sound")
sound2.SoundId = "rbxassetid://301964312"
 
-- create a table of assets to be loaded
local assets = {
	sound,
	sound2
}
 
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")

 


developer.roblox.com/en-us/api-reference/class/ContentProvider

 

ContentProvider

This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on t

developer.roblox.com

developer.roblox.com/en-us/api-reference/function/ContentProvider/PreloadAsync

 

ContentProvider:PreloadAsync

This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on t

developer.roblox.com

developer.roblox.com/en-us/api-reference/property/ContentProvider/RequestQueueSize

 

ContentProvider.RequestQueueSize

This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on t

developer.roblox.com

 

'API 문서' 카테고리의 다른 글

WeldConstraints  (0) 2021.04.17
ManualWeld  (0) 2021.04.11
TweenService  (0) 2021.04.11
Debris  (0) 2021.04.11
UserInputService  (0) 2021.04.10

댓글