插入服務用於從 Roblox 網站插入資產,通常是 LoadAsset 函數。
要載入素材,必須由體驗的創建者可以存取它,這可能是使用者或群組。若體驗由不同的創作者上傳,資產數據將無法使用。請參閱 LoadAsset() 方法,了解有關此安全檢查的更多細節。請注意,您不應該 使用此服務載入 API 鑰匙或其他秘密 。使用 HttpService:GetSecret() 取代。
也見「也見」
- AssetService , 可以提供使用插入服務載入可能想要載入的資產的資訊
概要
方法
- CreateMeshPartAsync(meshId : ContentId,collisionFidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):MeshPart
創建一個新的 MeshPart 並設定指定的忠實度值。
從目型錄中取得免費裝飾列表。
從目型錄中取得免費模型的列表。
返回地方創建創作者創建的資產的最新資產版本ID。可與 InsertService:LoadAssetVersion() 一起使用來載入模型的最新版本,即使在遊戲運行時也是如此。
返回包含素材的 Model 。
返回插入到 InsertService 中的模型,包含指定的資產版本ID的資產。
屬性
AllowClientInsertModels
方法
CreateMeshPartAsync
創建一個新的 MeshPart 與指定的 CollisionFidelity 和 RenderFidelity 。因為 MeshPart.MeshId 是只讀的,這是一種方法來通過腳本創建一個 MeshPart 而不需要複製現有的方法。如果創建失敗,它會發出錯誤。
參數
網格資產 ID。
返回
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,等等。
參數
返回
包含在表中的單一表(返回的免費裝飾)。
範例程式碼
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() 函數。
參數
返回
一個單表(返回的免費模型)被包裝在一個表中。
範例程式碼
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() 一起使用來載入模型的最新版本,即使在遊戲運行時也是如此。
參數
返回
LoadAsset
載入資產功能會取得資產的ID並返回包含素材的Model。例如,要載入這個公共的 DogeModel,其資產ID為 *257489726 *,你可以使用:
local InsertService = game:GetService("InsertService")local Workspace = game:GetService("Workspace")local assetId = 257489726local model = InsertService:LoadAsset(assetId)model.Parent = Workspace
呼叫此函數可能會失敗,如果提供模型的伺服器發生問題。因此,一般來說,包裝這個函數的呼叫在 pcall 中捕捉這種錯誤是一個好主意。
local InsertService = game:GetService("InsertService")local Workspace = game:GetService("Workspace")local assetId = 257489726local success, model = pcall(InsertService.LoadAsset, InsertService, assetId)if success and model thenprint("Model loaded successfully")model.Parent = Workspaceelseprint("Model failed to load!")end
安全檢查
由此函數載入的資產必須是 創建或擁有 由遊戲創作者或 Roblox 創建或擁有。此外,像 T 恤、襯衫、褲子和虛擬人偶配件等無害的資產類型,可以從任何遊戲載入,因為它們是公開共的。
也見:
- AssetService:GetBundleDetailsAsync() , 查找哪些資產與組合相關。
- 對於插件,請參閱 DataModel:GetObjects()
參數
正在載入的資產的資產ID。
返回
載入的素材的實例。
範例程式碼
local InsertService = game:GetService("InsertService")
local ASSET_ID = 82353
local asset = InsertService:LoadAsset(ASSET_ID)
asset.Parent = workspace
LoadAssetVersion
返回插入到 InsertService 中的模型,包含指定的資產版本ID的資產。
參數
返回
範例程式碼
local InsertService = game:GetService("InsertService")
local ASSET_VERSION_ID = 296050499
local asset = InsertService:LoadAssetVersion(ASSET_VERSION_ID)
asset.Parent = game.Workspace