InsertService

顯示已棄用項目

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

無法建立
服務

插入服務用於從 Roblox 網站插入資產,通常是 LoadAsset 函數。

要載入素材,必須由體驗的創建者可以存取它,這可能是使用者或群組。若體驗由不同的創作者上傳,資產數據將無法使用。請參閱 LoadAsset() 方法,了解有關此安全檢查的更多細節。請注意,您不應該 使用此服務載入 API 鑰匙或其他秘密 。使用 HttpService:GetSecret() 取代。

也見「也見」

  • AssetService , 可以提供使用插入服務載入可能想要載入的資產的資訊

概要

方法

屬性

AllowClientInsertModels

無法建立指令碼
平行讀取

方法

CreateMeshPartAsync

暫停

創建一個新的 MeshPart 與指定的 CollisionFidelityRenderFidelity 。因為 MeshPart.MeshId 是只讀的,這是一種方法來通過腳本創建一個 MeshPart 而不需要複製現有的方法。如果創建失敗,它會發出錯誤。

參數

meshId: ContentId

網格資產 ID。

預設值:""
collisionFidelity: Enum.CollisionFidelity
預設值:""
renderFidelity: Enum.RenderFidelity
預設值:""

返回

新的 MeshPart 實個體、實例。

GetFreeDecals

暫停

取得免費裝飾功能會從目型錄中恢復一個列表的免費裝飾Decals。這個方法的返回類型很奇怪,因為它返回一個包裝在表中的單一表。

最好的方法是顯示返回的數組的視覺效果:


[1] = {
CurrentStartIndex = 1, -- 這可以根據你輸入的頁面而變化。
TotalCount = 21, -- 永遠是 21。
Results = {
-- 這裡所有參數都是假的。它們可以根據資產而變化。
[1] = {
Name = "Asset Name",
AssetId = 0000000,
AssetVersionId = 0000000,
CreatorName = "Roblox",
},
-- [2]、[3]、等等…最多到 [21]
},
}

在這個頁面底部提供了循環過這個列表的範例。

此外,如果你想要插入 Models 而不是,你可以使用 InsertService:GetFreeModels() 函數。

注意:: 頁面參數從 0 開始。因此頁面 1=0,頁面 2=1,等等。

參數

searchText: string

用於在目型錄中尋找免費貼花的字串。

預設值:""
pageNum: number

目錄中要傳回回的頁面編號。

預設值:""

返回

包含在表中的單一表(返回的免費裝飾)。

範例程式碼

InsertService:GetFreeDecals

local InsertService = game:GetService("InsertService")
local page = unpack(InsertService:GetFreeDecals("Cats", 0)) -- Search for "Cats" on Page 1.
for i = 1, page.TotalCount do
local item = page.Results[i]
print("Item #" .. i)
for key, value in pairs(item) do
print(" " .. key .. ": " .. value)
end
end

GetFreeModels

暫停

取得免費模型功能會從目型錄中恢復一個列表的免費 Models。這個方法的返回類型很奇怪,因為它返回一個包裝在表中的單一表。

最好的方法是顯示返回的數組的視覺效果:


[1] = {
CurrentStartIndex = 1, -- 這可以根據你輸入的頁面而變化。
TotalCount = 21, -- 永遠是 21。
Results = {
-- 這裡所有參數都是假的。它們可以根據資產而變化。
[1] = {
Name = "Asset Name",
AssetId = 0000000,
AssetVersionId = 0000000,
CreatorName = "Roblox",
}
-- [2]、[3]、等等…最多到 [21]
}
}

在這個頁面底部提供了循環過這個列表的範例。

此外,如果您想插入免費的 Decals,您可以使用 InsertService:GetFreeDecals() 函數。

參數

searchText: string

用於在目型錄中尋找免費貼花的字串。

預設值:""
pageNum: number

目錄中要傳回回的頁面編號。

預設值:""

返回

一個單表(返回的免費模型)被包裝在一個表中。

範例程式碼

InsertService:GetFreeModels

local InsertService = game:GetService("InsertService")
local page = unpack(InsertService:GetFreeModels("Cats", 0)) -- Search for "Cats" on Page 1.
for i = 1, page.TotalCount do
local item = page.Results[i]
print("Item #" .. i)
for key, value in pairs(item) do
print(" " .. key .. ": " .. value)
end
end

GetLatestAssetVersionAsync

暫停

返回地方創建創作者創建的資產的最新資產版本ID。可與 InsertService:LoadAssetVersion() 一起使用來載入模型的最新版本,即使在遊戲運行時也是如此。

參數

assetId: number
預設值:""

返回

LoadAsset

暫停

載入資產功能會取得資產的ID並返回包含素材的Model。例如,要載入這個公共的 DogeModel,其資產ID為 *257489726 *,你可以使用:


local InsertService = game:GetService("InsertService")
local Workspace = game:GetService("Workspace")
local assetId = 257489726
local model = InsertService:LoadAsset(assetId)
model.Parent = Workspace

呼叫此函數可能會失敗,如果提供模型的伺服器發生問題。因此,一般來說,包裝這個函數的呼叫在 pcall 中捕捉這種錯誤是一個好主意。


local InsertService = game:GetService("InsertService")
local Workspace = game:GetService("Workspace")
local assetId = 257489726
local success, model = pcall(InsertService.LoadAsset, InsertService, assetId)
if success and model then
print("Model loaded successfully")
model.Parent = Workspace
else
print("Model failed to load!")
end

安全檢查

由此函數載入的資產必須是 創建或擁有 由遊戲創作者或 Roblox 創建或擁有。此外,像 T 恤、襯衫、褲子和虛擬人偶配件等無害的資產類型,可以從任何遊戲載入,因為它們是公開共的。

也見:

參數

assetId: number

正在載入的資產的資產ID。

預設值:""

返回

載入的素材的實例。

範例程式碼

InsertService:LoadAsset

local InsertService = game:GetService("InsertService")
local ASSET_ID = 82353
local asset = InsertService:LoadAsset(ASSET_ID)
asset.Parent = workspace

LoadAssetVersion

暫停

返回插入到 InsertService 中的模型,包含指定的資產版本ID的資產。

參數

assetVersionId: number
預設值:""

返回

範例程式碼

InsertService:LoadAssetVersion

local InsertService = game:GetService("InsertService")
local ASSET_VERSION_ID = 296050499
local asset = InsertService:LoadAssetVersion(ASSET_VERSION_ID)
asset.Parent = game.Workspace

活動