InsertService

显示已弃用

*此内容使用人工智能(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

活动