AssetService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務

資產服務 是一個非重複的服務,用於處理與資產相關的查詢到 Roblox 網頁 API。

概要

方法

屬性

方法

CreateEditableImage

創建新的 EditableImage 。默認解析度設為 512×512,但您可以使用方法的選項表格指定不同的尺寸。

如果裝置特定的可編輯記憶預算已用盡,創建失敗,此方法返回 nil

參數

editableImageOptions: Dictionary

包含方法控件的選項表:

  • Size – 一個 Vector2 指定圖像所需的寬度和高度。
預設值:""

返回

CreateEditableMesh

創建一個新的、空的 EditableMesh 。垂直、三角形和其特性可以動態地添加到它。如果裝置特定的可編輯記憶預算已用盡,創建將失敗,此方法將返回 nil

參數

editableMeshOptions: Dictionary

包含創建的EditableMesh的選項表。目前沒有可用的選項,因為 將永遠是空白可編輯網格。

預設值:""

返回

CreateSurfaceAppearance

參數

content: Dictionary
預設值:""

返回

CreateAssetAsync

暫停

從指定對物件上傳新資產到 Roblox。

目前,此方法只能在本地載入的插件和上傳資產時使用,而不需要先提示。

參數

object: Object

要創建為素材的對象。

預設值:""
assetType: Enum.AssetType

目前支持的類型是:

預設值:""
requestParameters: Dictionary

包含資產元數據的選項表:

  • Name - 資產名稱作為字串。默認為 [object.Name]
  • Description – 資產的說明為字串。默認為 "Created with AssetService:CreateAssetAsync"
  • CreatorId – 資產創建者的ID作為數字。預設登錄到 Roblox Studio 使用者的插件上下文。需要開啟雲端 Luau 執行上下文。
  • CreatorTypeEnum.AssetCreatorType 指示資產創建創作者類型。在插件上下文中預設為 Enum.AssetCreatorType.User 。需要開啟雲端 Luau 執行上下文。
  • IsPackage – 布林值,只適用於 Enum.AssetType.Model 輸入。默認為 true
預設值:"nil"

返回

如果成功,則為 Enum.CreateAssetResult 和資產 ID 對組。

範例程式碼

The following code creates a Mesh asset from an EditableMesh.

AssetService:CreateAssetAsync

local AssetService = game:GetService("AssetService")
local editableMesh = AssetService:CreateEditableMesh()
-- add vertices, faces, and uvs to the mesh
local requestParameters = {
CreatorId = 123,
CreatorType = Enum.AssetCreatorType.User,
Name = "My asset",
Description = "a good asset",
}
local ok, result, idOrUploadErr = pcall(function()
return AssetService:CreateAssetAsync(editableMesh, Enum.AssetType.Mesh, requestParameters)
end)
if not ok then
warn(`error calling CreateAssetAsync: {result}`)
elseif result == Enum.CreateAssetResult.Success then
print(`success, new asset id: {idOrUploadErr}`)
else
warn(`upload error in CreateAssetAsync: {result}, {idOrUploadErr}`)
end

CreateAssetVersionAsync

暫停

從指定對物件上傳新版本的現有資產。

目前,此方法只能在本地載入的插件和上傳資產時使用,而不需要先提示。

參數

object: Object

要創建為素材的對象。

預設值:""
assetType: Enum.AssetType

目前支持的類型是:

預設值:""
assetId: number

新版本的資產ID。

預設值:""
requestParameters: Dictionary

包含資產元數據的選項表:

  • Name – 一個 string 。素材名稱。默認值:物件bject.Name。
  • Description – 一個 string 。素材的說明。預設:「使用資產服務創建資產Async」。
  • CreatorId – A number .資產創建創作者的ID。預設:登录的 Roblox Studio 用戶對於插件上下文。需要開啟雲端 Luau 執行上下文。
  • CreatorType – 一個 Enum.AssetCreatorType 。資產創建創作者類型。默認值:Enum.AssetCreatorType.User 在插件上下文中。需要開啟雲端 Luau 執行上下文。
  • IsPackage – 一個 bool 。只適用於 Enum.AssetType.Model 輸入。默認值:真。
預設值:"nil"

返回

如果成功,則 Enum.CreateAssetResult 和資產版本號碼對組成對應。

範例程式碼

The following code creates a new Model asset version.

AssetService:CreateAssetVersionAsync

local AssetService = game:GetService("AssetService")
local assetIdToUpdate = 321
local model = Instance.new("Model")
local requestParameters = {
CreatorId = 123,
CreatorType = Enum.AssetCreatorType.User,
}
local ok, result, versionOrUploadErr = pcall(function()
return AssetService:CreateAssetVersionAsync(model, Enum.AssetType.Model, assetIdToUpdate, requestParameters)
end)
if not ok then
warn(`error calling CreateAssetVersionAsync: {result}`)
elseif result == Enum.CreateAssetResult.Success then
print(`success, new asset version: {versionOrUploadErr}`)
else
warn(`upload error in CreateAssetVersionAsync: {result}, {versionOrUploadErr}`)
end

CreateEditableImageAsync

暫停

創建一個新的 EditableImage 對象,擁有指定的紋理。非資產紋理ID,例如rbxthumb://,是支持的。如果使用圖像素材,它必須與體驗創作者相關並/或擁有,或者必須在體驗中創建。如果裝置特定的可編輯記憶預算已用盡,創建將失敗,此方法將返回 nil

查看 EditableImage 文件,了解使用此 API 時的特殊考慮因素。

參數

content: Content

參考儲存在外部或作為空間置內物件的資產內容,包裝單個值之一的支持的 Enum.ContentSourceType 值。

預設值:""
editableImageOptions: Dictionary

包含創建的 EditableImage 的選項表。目前無法使用選項,因為不支持縮放 via Size

預設值:""

返回

新的 EditableImage 包含提供的圖像。

CreateEditableMeshAsync

暫停

返回從現有 EditableMesh 或網格 EditableMesh ID 創建的新對象 Content。預設情況下,從此方法創建的 EditableMesh 將固定大小,使網格數據只能修改而不能添加或移除。固定尺寸的 EditableMesh 消耗較少的記憶,並應在可能的情況下盡量使用。

如果裝置特定的可編輯記憶預算已用盡,創建將失敗,此方法將返回 nil

請參閱 啟用可編輯網格對已發布體驗的啟用權限 部分的 EditableMesh 以獲得使用此 API 時的特殊考慮。

參數

content: Content

參考儲存在外部或作為空間置內物件的資產內容,包裝單個值之一的支持的 Enum.ContentSourceType 值。

預設值:""
editableMeshOptions: Dictionary

包含方法控件的選項表:

  • FixedSize – A bool .預設值為 true ,返回的 EditableMesh 將無法讓您添加或移除邊點,只能修改它們的值。如果需要更改網格結構,設為 false ,以犧牲使用更多記憶。
預設值:""

返回

新的 EditableMesh 實個體、實例。

CreateMeshPartAsync

暫停

這個方法創建了一個 MeshPart 與指定的 CollisionFidelity , RenderFidelityFluidFidelity 。因為 MeshPart.MeshId 是只讀的,這個方法是用於通過腳本創建任何網格ID的網格,而不需要複製現有的 MeshPart 。如果創建失敗,它會發出錯誤。

參數

meshContent: Content

參考儲存在外部或作為空間置內物件的資產內容,包裝單個值之一的支持的 Enum.ContentSourceType 值。

預設值:""
options: Dictionary

包含方法的一個或多個控件選項表:

預設值:"nil"

返回

CreatePlaceAsync

暫停

通過指定的 templatePlaceID 複製一個地方,並返回新空間方的 PlaceId,您可以使用 TeleportService 來使用。複製位置會顯示在空間置創建者的庫存中,具有指定的名稱和說明。

請注意,樣板位置必須通過位置設置啟用樣板複製。你不能使用此方法來複製你沒擁有的樣板位置。

不建議過度使用此 API,特別是如果創建的地點包含腳本,因為快速更新代碼在大量地點上變得不可行。對於使用者生成的世界,請考慮將使用者創作 serialize 並將其保存在 DataStores 中。

參數

placeName: string

新空間點的名稱。

預設值:""
templatePlaceID: number

PlaceId 的地方以複製。

預設值:""
description: string

新地空間的說明。

預設值:""

返回

PlaceId 新空間置的。

CreatePlaceInPlayerInventoryAsync

暫停

參數

player: Instance
預設值:""
placeName: string
預設值:""
templatePlaceID: number
預設值:""
description: string
預設值:""

返回

GetAssetIdsForPackage

暫停

返回包含指定包裝中的資產ID陣列。

參數

packageAssetId: number
預設值:""

返回

包含指定包裝中的資產ID。

GetAudioMetadataAsync

暫停

提供與特定音源(藝術家、標題、時間、類輸入等)相關的元數據。

參數

idList: Array

用於恢復元數據的資產或內容ID數組。最大批量大小為 30。

預設值:""

返回

與請邀請相同順序的字典表陣列,每個字典包含其資產/內容的下列元數據:

  • AssetId (字串)

  • Title (字串)

  • Artist (字串)

  • Duration (數字) 在秒內

  • AudioType ( Enum.AudioSubType )

請注意,如果在請求的資產中獲取元數據時發生錯誤,例如資產ID不存在,其辭典表仍包含在返回的數組中,但只包含AssetId字段用於參考目的。此外,如果給定的資產無法確定 AudioType (可能因為它是私人音訊),結果辭典將不包含AudioType條目。

範例程式碼


local AssetService = game:GetService("AssetService")
local SoundService = game:GetService("SoundService")
local trackIDs = {
SoundService.Sound1.SoundId,
SoundService.Sound2.SoundId,
SoundService.Sound3.SoundId,
SoundService.Sound4.SoundId,
}
local success, result = pcall(function()
return AssetService:GetAudioMetadataAsync(trackIDs)
end)
if success then
for i = 1, #trackIDs do
local contentId = "rbxassetid://" .. result[i].AssetId
if trackIDs[i] == contentId then
print(result[i].Title, "by", result[i].Artist)
else
warn("No metadata fetched for requested asset #" .. tostring(i))
end
end
end

GetBundleDetailsAsync

暫停

此功能返回指定組合的內容詳情。

如果包裝 ID 不存在,它會投擲 HTTP 400 (Bad Request) 。如果 bundleId 無法轉換為整數,它會投擲 Unable to cast string to int64

參數

bundleId: number

指定組合的 ID。

預設值:""

返回

包含以下鑰值對的辭典,包含有關指定包的詳細信息:

  • Id — 包裝 ID (與傳送的 bundleId 引數數相同)

  • Name — 包裝名稱

  • Description — 包裝說明

  • BundleType — 代表 Enum.BundleType 的字串,例如 "BodyParts""DynamicHead"

  • Items — 包裝中的項目數組,每個都有通過以下鑰匙來表示的詳情:

    • Id — 項目ID

    • Name — 項目名稱

    • Type — 物品類型,例如 "Asset"

範例程式碼

Getting Bundle Details

local AssetService = game:GetService("AssetService")
local BUNDLE_ID = 14
local success, result = pcall(function()
return AssetService:GetBundleDetailsAsync(BUNDLE_ID)
end)
if success then
print(result)
--[[
{
["BundleType"] = "BodyParts",
["Description"] = "The year is 5003, Battlebot 5000 must face his mightiest foe, or face becoming obsolete.",
["Id"] = 14,
["Items"] = {
[1] = {...},
[2] = {
["Id"] = 1678225030,
["Name"] = "SinisterBot 5001 Left Arm",
["Type"] = "Asset"
},
[3] = {...},
[4] = {...},
[5] = {...},
[6] = {...},
[7] = {...}
},
["Name"] = "SinisterBot 5001"
}
--]]
end

GetGamePlacesAsync

暫停

返回包含名稱和 PlaceId 當前體驗內的地點的 StandardPages 對象。


返回

範例程式碼

The following code prints the name and PlaceId of each place in the experience.

AssetService:GetGamePlacesAsync

local AssetService = game:GetService("AssetService")
local placePages = AssetService:GetGamePlacesAsync()
while true do
for _, place in placePages:GetCurrentPage() do
print("Name:", place.Name)
print("PlaceId:", place.PlaceId)
end
if placePages.IsFinished then
break
end
placePages:AdvanceToNextPageAsync()
end

PromptCreateAssetAsync

暫停

允許在體驗中創建資產,以提示發布對話框。當呼叫時,它向使用者提供對話框,讓他們輸入名稱、說明和預覽素材。提交後,會將資產保存到使用者的道具欄中。只能在服務器端呼叫。

參數

player: Player

提交資產作品建的使用者。

預設值:""
instance: Instance

要創建的資產。目前無法包含腳本或孵化非公共資產。

預設值:""
assetType: Enum.AssetType

資產類輸入。目前只能是 Enum.AssetType.Model

預設值:""

返回

如果成功,則為 Enum.PromptCreateAssetResult 和資產 ID 對組。

PromptImportAnimationClipFromVideoAsync

暫停

參數

player: Player
預設值:""
progressCallback: function
預設值:""

返回

SavePlaceAsync

()
暫停

保存當前位空間的狀態。僅適用於使用 AssetService:CreatePlaceAsync() 創建的位置或通過位置設置啟用 API 的位置。


返回

()

SearchAudio

暫停

返回包含給定搜搜尋結果的 AudioPages 對象。不會返回空值的欄位。

請注意,此方法具有低 HTTP 請求限制,可能會發生錯誤,因此應始終包含在 pcall() 中以進行錯誤處理。可能的錯誤訊息包括:


<th>原因</th>
</tr>
</thead>
<tbody>
<tr>
<td>HTTP 429(要求過多)</td>
<td><code>Class.AssetService:SearchAudio()</code> 已被呼叫過多次。</td>
</tr>
<tr>
<td>數據類型不期望,預期的陣列獲得 null</td>
<td>關鍵字參數被過濾。</td>
</tr>
</tbody>
錯誤訊息

參數

searchParameters: AudioSearchParams
預設值:""

返回

範例程式碼

This code gets the music assets returned by the keyword "happy" and prints out their titles.

Getting Music Search Titles

local AssetService = game:GetService("AssetService")
local audioSearchParams = Instance.new("AudioSearchParams")
audioSearchParams.SearchKeyword = "happy"
local success, result = pcall(function()
return AssetService:SearchAudio(audioSearchParams)
end)
if success then
local currentPage = result:GetCurrentPage()
for _, audio in currentPage do
print(audio.Title)
end
else
warn("AssetService error: " .. result)
end
--[[ Returned data format
{
"AudioType": string,
"Artist": string,
"Title": string,
"Tags": {
"string"
},
"Id": number,
"IsEndorsed": boolean,
"Description": string,
"Duration": number,
"CreateTime": string,
"UpdateTime": string,
"Creator": {
"Id": number,
"Name": string,
"Type": number,
"IsVerifiedCreator": boolean
}
}
--]]

活動