Skip to content

AssetService ​

AssetService 资产服务,提供预加载资源与自定义资产管理。原预设管理能力已迁移至 PrefabService。

概览 ​

AssetService 是编辑器侧的资产服务,负责维护预加载资源清单,并提供官方资源检索、自定义资源导入导出、查询、删除、重命名、公开设置以及上传目录归类等能力。原先的预设创建、属性读写等能力已迁移至 PrefabService,可通过 editor:GetService("PrefabService") 获取预设服务,AssetService 上保留的旧预设接口虽仍可用,但已标记迁移。所有操作以资源标识为入口,官方资源使用 official:// 形式,用户生产内容使用 custom:// 形式。

Get by:

lua
-- @runtime editor
local service = editor:GetService("AssetService")

函数 ​

AddPreloadAsset ​

将指定资源 URI 加入预加载资源清单,并返回本次添加是否成功。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。

参数

参数类型说明
uriString完整资源 URI(custom://xxx / official://mesh/9833)

返回值

类型说明
Bool是否添加成功

添加调用方提供的预加载资源

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function addConfiguredPreload(uri)
    if type(uri) ~= "string" or uri:find("%s") then return false end
    if not uri:match("^custom://.+$") and not uri:match("^official://[^/]+/.+$") then
        print("请传入项目实际可用的完整 custom:// 或 official:// 资源 URI")
        return false
    end
    local success = assetService:AddPreloadAsset(uri)
    print("预加载添加结果:", success)
    return success
end
-- 由调用方传入真实资源 URI 后显式调用 addConfiguredPreload;本块不会自行调用。

RemovePreloadAsset ​

从预加载资源清单中移除指定资源 URI,并返回本次移除是否成功。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。移除时只传入自己管理且确认可移除的预加载项;不要自动删除项目既有预加载配置。

参数

参数类型说明
uriString完整资源 URI(custom://xxx / official://mesh/9833)

返回值

类型说明
Bool是否移除成功

移除调用方确认可移除的预加载项

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function removeOwnedPreload(uri)
    if type(uri) ~= "string" or uri:find("%s") then return false end
    if not uri:match("^custom://.+$") and not uri:match("^official://[^/]+/.+$") then
        print("请传入项目实际可用的完整 custom:// 或 official:// 资源 URI")
        return false
    end
    local success = assetService:RemovePreloadAsset(uri)
    print("预加载移除结果:", success)
    return success
end
-- 由调用方传入真实资源 URI 后显式调用 removeOwnedPreload;本块不会自行调用。

GetPreloadAssetList ​

获取当前预加载资源清单,返回由资源 URI 组成的数组。

返回值

类型说明
Array当前预加载资源清单(资源 URI 数组)

添加预加载资源并查看清单

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local addedPreset = assetService:AddPreloadAsset("official://preset/20001")
local addedImage = assetService:AddPreloadAsset("official://image/10000")
print("加入预加载清单结果:", addedPreset, addedImage)
local preloadList = assetService:GetPreloadAssetList()
if type(preloadList) == "table" then
    print("预加载资源数量:", #preloadList)
    for index, uri in ipairs(preloadList) do
        print(index, uri)
    end
else
    print("预加载资源清单不可用:", type(preloadList))
end

ExportCustomAsset ​

将指定自定义资产导出到给定路径,并返回本次导出是否成功。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。exportPath 由调用方提供真实可写输出路径;不要填写空串或猜测存在的目录。

参数

参数类型说明
assetIdString要导出的自定义资产 ID
exportPathString导出文件路径

返回值

类型说明
Bool是否导出成功

导出调用方指定的自定义资产元数据

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function exportOwnedAsset(assetId, exportPath)
    if type(assetId) ~= "string" or not assetId:match("%S") then return end
    if assetId:match("^official://") then
        print("请传入自己有权操作的自定义资产 ID")
        return
    end
    local info = assetService:GetAssetById(assetId)
    if info == nil then
        print("未找到指定自定义资产")
        return
    end
    if type(exportPath) ~= "string" or not exportPath:match("%S") then return end
    local success = assetService:ExportCustomAsset(assetId, exportPath)
    print("导出结果:", success)
    return success
end
-- 确认资产归属和输出路径后,显式调用 exportOwnedAsset(assetId, exportPath)。

ImportCustomAsset ​

根据 JSON 文件路径导入自定义资产,返回导入后的资源 ID,失败时返回空串。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。jsonPath 必须是调用方已经准备好的真实 JSON 文件路径;本例不创建或猜测本地文件。

参数

参数类型说明
jsonPathString要导入的 JSON 文件路径

返回值

类型说明
String资源ID(失败返回空串)

从调用方提供的 JSON 路径导入

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function importConfiguredAsset(jsonPath)
    if type(jsonPath) ~= "string" or not jsonPath:match("%S") then return end
    local assetId = assetService:ImportCustomAsset(jsonPath)
    if assetId == nil or assetId == "" then
        print("导入失败,请检查 JSON 文件与路径")
        return
    end
    print("已导入自定义资产:", assetId)
    return assetId
end
-- 确认输入文件为要导入的真实资源 JSON 后,显式调用 importConfiguredAsset(jsonPath)。

ListCustomAssets ​

列出当前用户上传的自定义资产,直接返回资产信息数组。可选参数依次是 assetType 与 folder;返回项包含 id、name、type、url、path、permission。

注意: 本例只读查询 Image 类型已加载的目录;先处理查询失败,再从 result.Folders 的 TagName 取真实目录名。空资产数组是合法结果,缓存未加载或请求失败不能当作没有资产。permission 仅表示返回的权限状态,不能替代写操作前的归属与授权确认。

参数

参数类型说明
assetTypeString可选;资源类型:Image / Audio / Mesh / Effect / Material / Animation / Skybox / Skin。不传返回全部类型
folderString可选;按已上传资源目录名过滤(需先调用 ListUploadedFolders 加载目录缓存);不传返回全部目录

返回值

类型说明
Array每项 { id = 资源ID, name = 资源名, type = 资源类型, url = 资源地址, path = 资源目录(如 已上传文件/默认分类), permission = 0受限/1公开 }

先加载目录缓存,再用 nil 占位执行仅目录过滤

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
-- 先查询 Image 类型目录,成功回调后目录缓存才可用于后续过滤。
assetService:ListUploadedFolders("Image", function(success, result)
    if type(result) ~= "table" then
        print("未取得有效目录查询结果:", success, result)
        return
    end
    if not success then
        print("目录查询失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
        return
    end
    if type(result.Folders) ~= "table" then
        print("目录结果缺少 Folders")
        return
    end
    -- 只读遍历已有目录;不自动移动、改名或删除资产。
    for _, folder in ipairs(result.Folders) do
        local folderName = folder.TagName
        -- 仅按目录过滤:第一个 assetType 参数显式传 nil,folderName 保持在第二位。
        local assets = assetService:ListCustomAssets(nil, folderName)
        if type(assets) == "table" then
            print("目录:", folder.TagId, folderName, "资产数:", #assets)
            for _, item in ipairs(assets) do
                print(item.id, item.name, item.type, item.path, item.permission)
            end
        else
            print("未取得该目录的资产数组:", folderName)
        end
    end
end)

ListReferencedAssets ​

获取当前被引用的资源 URI 列表。

返回值

类型说明
Array引用资源列表

查看项目引用的资源 URI 列表

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local referencedAssets = assetService:ListReferencedAssets()
if type(referencedAssets) == "table" then
    print("引用资源数量:", #referencedAssets)
    for index, uri in ipairs(referencedAssets) do
        print(index, uri)
    end
else
    print("引用资源列表不可用:", type(referencedAssets))
end

GetCustomAssetSize ​

获取指定自定义资产的大小,返回以字节为单位的数值。

参数

参数类型说明
assetIdString自定义资产 ID

返回值

类型说明
Int字节数

查询自定义资产大小

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local customAssets = assetService:ListCustomAssets()
if type(customAssets) == "table" then
    print("当前自定义资产数量:", #customAssets)
end
local assetId = "custom://demo"
print("查询自定义资产ID:", assetId)
local size = assetService:GetCustomAssetSize(assetId)
print("资产大小(字节):", size)

ListOfficialAssets ​

按资源类型列出官方资源,返回的每一项为包含 id、name、type、path 字段的表。

参数

参数类型说明
assetTypeString资源类型:Image / Audio / Mesh / Effect / Animation / Skybox(大小写不敏感)

返回值

类型说明
Array每项 { id = 资源ID(如 official://image/673016), name = 资源名, type = 资源类型, path = 资源目录(如 官方资源/基础形状;无目录为空串) }

列出官方图像与预设资源

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local imageAssets = assetService:ListOfficialAssets("image")
local presetAssets = assetService:ListOfficialAssets("preset")
if type(imageAssets) == "table" then
    print("官方图像资源数量:", #imageAssets)
    for index, item in ipairs(imageAssets) do
        if type(item) == "table" then
            print("图像", index, item.id, item.name, item.path)
        end
        if index >= 5 then
            break
        end
    end
else
    print("官方图像资源列表不可用")
end
if type(presetAssets) == "table" then
    print("官方预设资源数量:", #presetAssets)
    for index, item in ipairs(presetAssets) do
        if type(item) == "table" then
            print("预设", index, item.id, item.name, item.path)
        end
        if index >= 5 then
            break
        end
    end
else
    print("官方预设资源列表不可用")
end

GetAssetById ​

根据资源 ID 获取资产信息,返回包含 id、name、type、url、path、permission 字段的表;资产不存在或 不可用时返回 nil。

参数

参数类型说明
assetIdString资源 ID;自定义资产传裸 ID 或 custom:// 前缀,官方资源传 official://{类型}/{ID}(如 official://image/673016)

返回值

类型说明
Table资产信息 { id = 资源ID, name = 资源名, type = 资源类型, url = 资源地址, path = 资源目录(如 官方资源/基础形状 或 已上传文件/默认分类;无目录为空串), permission = 0受限/1公开 };官方资源 permission 恒为 1(公开)。资产不存在或 不可用时返回 nil。

按资产 ID 查询官方预设信息

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local assetId = "official://preset/20001"
local assetInfo = assetService:GetAssetById(assetId)
if type(assetInfo) == "table" then
    print("资产ID:", assetInfo.id)
    print("资产名:", assetInfo.name)
    print("资产类型:", assetInfo.type)
    print("资源地址:", assetInfo.url)
    print("资源目录:", assetInfo.path)
    print("权限(0受限/1公开):", assetInfo.permission)
else
    print("未查询到资产信息:", assetId)
end

GetAssetByName ​

按资源名模糊查找资产,可指定资源类型进行过滤,返回匹配到的资产信息表数组。

参数

参数类型说明
nameString资源名关键词,按名称子串包含匹配(忽略大小写)
assetTypeString可选;资源类型:Image / Audio / Mesh / Effect / Material / Animation / Skybox / Skin。不传查全部类型

返回值

类型说明
Array每项 { id = 资源ID, name = 资源名, type = 资源类型, url = 资源地址, path = 资源目录(如 官方资源/基础形状 或 已上传文件/默认分类;无目录为空串), permission = 0受限/1公开 }

按资源名模糊查找官方图像

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local officialImages = assetService:ListOfficialAssets("image")
local keyword = "形状"
if type(officialImages) == "table" and #officialImages > 0 then
    local firstImage = officialImages[1]
    if type(firstImage) == "table" and type(firstImage.name) == "string" then
        keyword = firstImage.name
    end
end
print("模糊查找关键词:", keyword)
local matchedAssets = assetService:GetAssetByName(keyword, "image")
if type(matchedAssets) == "table" then
    print("匹配到的资源数量:", #matchedAssets)
    for index, item in ipairs(matchedAssets) do
        if type(item) == "table" then
            print(index, item.id, item.name, item.type, item.path, item.permission)
        end
    end
else
    print("未返回匹配列表:", keyword)
end

DeleteAsset ​

删除指定的自定义资产,可选传入回调参数接收处理结果。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。删除会同步影响云端和本地且不可恢复。不得自动从用户资产列表选取目标,也不能把函数定义或请求提交视为删除成功。

参数

参数类型说明
assetIdString资源 ID(可传 custom:// 形式的 URI)
callbackFunction可选;callback(success, result),成功时 result.Succeeded 为已删除的资源 ID 列表,result.Failed 为失败明细

删除调用方确认可删除的自有资产

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function deleteOwnedAsset(assetId)
    if type(assetId) ~= "string" or not assetId:match("%S") then return end
    if assetId:match("^official://") then
        print("请传入自己有权操作的自定义资产 ID")
        return
    end
    local info = assetService:GetAssetById(assetId)
    if info == nil then
        print("未找到指定自定义资产")
        return
    end
    assetService:DeleteAsset(assetId, function(success, result)
        print("删除完成回调:", success, result)
        if type(result) == "table" then
            print("已删除列表:", result.Succeeded, "失败明细:", result.Failed)
        end
    end)
end
-- 删除不可恢复。确认资产属于自己且可以删除后,显式调用 deleteOwnedAsset(assetId)。

DeleteAssets ​

批量删除指定的多个自定义资产,可选传入回调参数接收处理结果。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须明确传入自己有权删除且已确认可删除的自定义资产 ID 非空数组。输入格式检查与 GetAssetById 查询不能证明资产归属、权限或删除成功。删除会同步影响云端和本地且不可恢复;不得自动从用户资产列表选取目标。函数定义或请求提交不代表删除已经执行或成功,实际结果以异步完成回调中的 Succeeded、Failed 或 ErrorMessage 为准。

参数

参数类型说明
assetIdsArray资源 ID 列表(可传 custom:// 形式的 URI)
callbackFunction可选;callback(success, result),成功时 result.Succeeded 为已删除的资源 ID 列表,result.Failed 为失败明细

删除调用方逐项确认可删除的自有资产

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function deleteOwnedAssets(assetIds)
    if type(assetIds) ~= "table" or #assetIds == 0 then return end
    local verifiedIds = {}
    local count = 0
    for index, assetId in pairs(assetIds) do
        if type(index) ~= "number" or index % 1 ~= 0 or index < 1 or index > #assetIds then return end
        if type(assetId) ~= "string" or not assetId:match("%S") then return end
        if assetId:match("^official://") then
            print("请传入自己有权删除的自定义资产 ID 列表")
            return
        end
        if assetService:GetAssetById(assetId) == nil then
            print("未找到指定自定义资产:", assetId)
            return
        end
        verifiedIds[index] = assetId
        count = count + 1
    end
    if count ~= #assetIds then return end
    assetService:DeleteAssets(verifiedIds, function(success, result)
        print("批量删除完成回调:", success, result)
        if type(result) == "table" then
            for _, assetId in ipairs(result.Succeeded or {}) do
                print("已删除:", assetId)
            end
            for _, failure in ipairs(result.Failed or {}) do
                print("删除失败:", failure.Id, failure.Msg)
            end
            if result.ErrorMessage ~= nil then
                print("请求错误:", result.ErrorMessage)
            end
        end
    end)
end
-- 本例仅定义函数,不执行删除,也不自动选择用户资产。
-- 删除不可恢复。逐项确认资产归属和可删除性后,调用方才能显式调用 deleteOwnedAssets(assetIds)。

RenameAsset ​

重命名指定的自定义资产,可选传入回调参数接收处理结果。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。名称修改会同步到云端和本地;应通过回调观察实际结果。

参数

参数类型说明
assetIdString资源 ID(可传 custom:// 形式的 URI)
newNameString新的资源名
callbackFunction可选;callback(success, result),成功时 result 含 AssetId / Name

重命名调用方指定的自有资产

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function renameOwnedAsset(assetId, newName)
    if type(assetId) ~= "string" or not assetId:match("%S") then return end
    if assetId:match("^official://") then
        print("请传入自己有权操作的自定义资产 ID")
        return
    end
    local info = assetService:GetAssetById(assetId)
    if info == nil then
        print("未找到指定自定义资产")
        return
    end
    if type(newName) ~= "string" or not newName:match("%S") then return end
    assetService:RenameAsset(assetId, newName, function(success, result)
        print("重命名完成回调:", success, result)
        if success and type(result) == "table" then
            print("资产 ID:", result.AssetId, "当前名称:", result.Name)
        end
    end)
end
-- 确认资产归属和目标名称后,显式调用 renameOwnedAsset(assetId, newName)。

SetAssetPublic ​

将指定的自定义资产设置为公开,可选传入回调参数接收处理结果。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方必须传入项目实际可用且自己有权操作的资源。输入格式检查不能证明资源权限、文件存在或操作成功;真实结果以返回值或完成回调为准。公开后所有人可用,不能恢复为私有;不要自动选取现有资产执行公开。

参数

参数类型说明
assetIdString资源 ID(可传 custom:// 形式的 URI)
callbackFunction可选;callback(success, result),成功时 result 含 AssetId

公开调用方确认可公开的自有资产

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function publishOwnedAsset(assetId)
    if type(assetId) ~= "string" or not assetId:match("%S") then return end
    if assetId:match("^official://") then
        print("请传入自己有权操作的自定义资产 ID")
        return
    end
    local info = assetService:GetAssetById(assetId)
    if info == nil then
        print("未找到指定自定义资产")
        return
    end
    assetService:SetAssetPublic(assetId, function(success, result)
        print("公开状态修改完成回调:", success, result)
        if success and type(result) == "table" then
            print("已处理资产 ID:", result.AssetId)
        end
    end)
end
-- 公开后不能恢复为私有。确认该自有资产允许公开后,显式调用 publishOwnedAsset(assetId)。

EnsureUploadedFolder ​

确保指定资源类型下的目录存在,不存在时创建;该接口没有直接返回值。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方须显式传入自己有权操作且真实存在或准备创建的目录/自定义资产。目录属于账号/服务器共享分类,不随地图保存。输入检查不能证明资源存在、归属或权限;以完成回调的 success 与 result 为准。 resType 使用 Image、Audio、Effect 或 Mesh;目录名由调用方明确指定。 同名目录复用,目录名不含点号。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
folderNameString目录名(同名复用,不含点号)
callbackFunctioncallback(success, result):成功 result 为 { TagId, TagName };失败为 { Operation, ErrorCode, ErrorMessage }

按调用方配置确认目录并读取正式结果

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function ensureOwnedFolder(resType, folderName)
    if type(resType) ~= "string" or resType == "" then return end
    if type(folderName) ~= "string" or not folderName:match("%S") then return end
    assetService:EnsureUploadedFolder(resType, folderName,
        function(success, result)
            if type(result) ~= "table" then
                print("未取得有效操作结果:", success, result)
                return
            end
            if not success then
                print("操作失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
                return
            end
            print("目录确认结果:", result.TagId, result.TagName)
        end)
end
-- 确认有权创建或复用该目录后,由调用方显式调用 ensureOwnedFolder(resType, folderName)。

MoveAssetsToUploadedFolder ​

把调用方指定的自定义资产移入指定目录,目录不存在时先创建;没有直接返回值。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方须显式传入自己有权操作且真实存在或准备创建的目录/自定义资产。目录属于账号/服务器共享分类,不随地图保存。输入检查不能证明资源存在、归属或权限;以完成回调的 success 与 result 为准。 resType 使用 Image、Audio、Effect 或 Mesh;目录名由调用方明确指定。 assetIds 必须是调用方逐项确认的连续非空数组,元素为裸 ID 或 custom:// URI;不得自动选取账号既有资产。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
folderNameString目录名(同名复用,不含点号)
assetIdsArray资源 ID 列表(裸 id 或 custom://<id>)
callbackFunctioncallback(success, result):成功 result 为 { TagId, TagName, Moved };失败为 { Operation, ErrorCode, ErrorMessage }

移动调用方明确指定的自有资产

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function moveOwnedAssetsToFolder(resType, folderName, assetIds)
    if type(resType) ~= "string" or resType == "" then return end
    if type(folderName) ~= "string" or not folderName:match("%S") then return end
    if type(assetIds) ~= "table" or #assetIds == 0 then return end
    for _, assetId in ipairs(assetIds) do
        if type(assetId) ~= "string" or not assetId:match("%S") then return end
        if assetId:match("^official://") then return end
    end
    assetService:MoveAssetsToUploadedFolder(resType, folderName, assetIds,
        function(success, result)
            if type(result) ~= "table" then
                print("未取得有效操作结果:", success, result)
                return
            end
            if not success then
                print("操作失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
                return
            end
            print("移入结果:", result.TagId, result.TagName, result.Moved)
        end)
end
-- 确认目录及每个自定义资产均有权调整后,显式调用 moveOwnedAssetsToFolder(resType, folderName, assetIds)。
-- 本例不从账号列表自动选择资产,不自动执行移动。

RemoveUploadedFolder ​

移除调用方指定的已上传资源目录,仅删除目录,不删除其中资源;目录不存在时视为成功。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方须显式传入自己有权操作且真实存在或准备创建的目录/自定义资产。目录属于账号/服务器共享分类,不随地图保存。输入检查不能证明资源存在、归属或权限;以完成回调的 success 与 result 为准。 resType 使用 Image、Audio、Effect 或 Mesh;目录名由调用方明确指定。 仅删目录与连同资源一起删除是不同操作。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
folderNameString目录名(同名复用,不含点号)
callbackFunctioncallback(success, result):成功 result 为 { TagName, Removed };失败为 { Operation, ErrorCode, ErrorMessage }

移除调用方确认可移除的目录

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function removeOwnedFolder(resType, folderName)
    if type(resType) ~= "string" or resType == "" then return end
    if type(folderName) ~= "string" or not folderName:match("%S") then return end
    assetService:RemoveUploadedFolder(resType, folderName,
        function(success, result)
            if type(result) ~= "table" then
                print("未取得有效操作结果:", success, result)
                return
            end
            if not success then
                print("操作失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
                return
            end
            print("目录移除结果:", result.TagName, result.Removed)
        end)
end
-- 确认自己有权移除该共享目录后,显式调用 removeOwnedFolder(resType, folderName)。
-- 不从查询结果自动选取首个目录,不自动执行移除。

ListUploadedFolders ​

查询指定资源类型下的全部已上传资源目录,结果通过回调提供,没有直接返回值。

注意: 本例只读查询 Image 类型目录,不创建、移动、改名或删除资源。空 Folders 是合法查询结果;查询失败不能当作空目录。目录属于账号/服务器共享分类,不随地图保存。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
callbackFunctioncallback(success, result):成功 result 为 { Folders = { { TagId, TagName }, ... } };失败为 { Operation, ErrorCode, ErrorMessage }

读取目录结果中的 Folders、TagId 和 TagName

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
assetService:ListUploadedFolders("Image", function(success, result)
    if type(result) ~= "table" then
        print("未取得有效目录查询结果:", success, result)
        return
    end
    if not success then
        print("目录查询失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
        return
    end
    local folders = result.Folders
    if type(folders) ~= "table" then
        print("目录结果缺少 Folders")
        return
    end
    print("Image 类型目录数:", #folders)
    for _, folder in ipairs(folders) do
        print("目录 ID:", folder.TagId, "目录名:", folder.TagName)
    end
end)

RenameUploadedFolder ​

按当前目录名定位并重命名已上传资源目录;目录不存在则失败,没有直接返回值。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方须显式传入自己有权操作且真实存在或准备创建的目录/自定义资产。目录属于账号/服务器共享分类,不随地图保存。输入检查不能证明资源存在、归属或权限;以完成回调的 success 与 result 为准。 resType 使用 Image、Audio、Effect 或 Mesh;目录名由调用方明确指定。 应先确认当前目录名与目标名称,避免误改账号共享目录。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
folderNameString要重命名的目录当前名称
newNameString新的目录名
callbackFunctioncallback(success, result):成功 result 为 { TagId, TagName };失败为 { Operation, ErrorCode, ErrorMessage }

重命名调用方明确指定的目录

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function renameOwnedFolder(resType, folderName, newName)
    if type(resType) ~= "string" or resType == "" then return end
    if type(folderName) ~= "string" or not folderName:match("%S") then return end
    if type(newName) ~= "string" or not newName:match("%S") then return end
    assetService:RenameUploadedFolder(resType, folderName, newName,
        function(success, result)
            if type(result) ~= "table" then
                print("未取得有效操作结果:", success, result)
                return
            end
            if not success then
                print("操作失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
                return
            end
            print("目录改名结果:", result.TagId, result.TagName)
        end)
end
-- 确认有权修改该共享目录后,显式调用 renameOwnedFolder(resType, folderName, newName)。
-- 本例不从账号查询结果自动选择目录,不自动执行改名。

MoveAssetsOutOfUploadedFolder ​

把指定自定义资产移出所在目录并回到默认分类,不删除资源;没有直接返回值。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方须显式传入自己有权操作且真实存在或准备创建的目录/自定义资产。目录属于账号/服务器共享分类,不随地图保存。输入检查不能证明资源存在、归属或权限;以完成回调的 success 与 result 为准。 resType 使用 Image、Audio、Effect 或 Mesh;assetIds 是调用方逐项确认的连续非空数组,元素为裸 ID 或 custom:// URI。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
assetIdsArray资源 ID 列表(裸 id 或 custom://<id>)
callbackFunctioncallback(success, result):成功 result 为 { Moved };失败为 { Operation, ErrorCode, ErrorMessage }

移出调用方明确指定的自有资产并消费 Moved

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function moveOwnedAssetsOutOfFolder(resType, assetIds)
    if type(resType) ~= "string" or resType == "" then return end
    if type(assetIds) ~= "table" or #assetIds == 0 then return end
    for _, assetId in ipairs(assetIds) do
        if type(assetId) ~= "string" or not assetId:match("%S") then return end
        if assetId:match("^official://") then return end
    end
    assetService:MoveAssetsOutOfUploadedFolder(resType, assetIds,
        function(success, result)
            if type(result) ~= "table" then
                print("未取得有效操作结果:", success, result)
                return
            end
            if not success then
                print("操作失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
                return
            end
            print("移出目录结果:", result.Moved)
        end)
end
-- 确认每个自定义资产均有权调整后,显式调用 moveOwnedAssetsOutOfFolder(resType, assetIds)。
-- 本例不自动枚举或移动账号既有资产;不得把请求列表当作已移动列表。

RemoveUploadedFolderWithAssets ​

删除指定已上传资源目录及其中全部资源;操作不可恢复,目录不存在时视为成功,没有直接返回值。

注意: 本例仅定义局部函数,不自动执行资产操作;调用方须显式传入自己有权操作且真实存在或准备创建的目录/自定义资产。目录属于账号/服务器共享分类,不随地图保存。输入检查不能证明资源存在、归属或权限;以完成回调的 success 与 result 为准。 resType 使用 Image、Audio、Effect 或 Mesh;目录名由调用方明确指定。 删除不可恢复,调用前须逐项确认目录和内部资源的归属及可删除性;仅删除目录请使用 RemoveUploadedFolder。

参数

参数类型说明
resTypeString资源类型:Image / Audio / Effect / Mesh。皮肤、动画、csb、天空盒有各自专用管线(PublishService 的 PublishAnimationAsync / PublishCsb / PublishSkybox),直传会得到不完整资产。
folderNameString目录名(不含点号)
callbackFunctioncallback(success, result):成功 result 为 { TagId, TagName, Removed, DeletedAssets };失败为 { Operation, ErrorCode, ErrorMessage }

删除调用方确认有权删除的目录及内部资源

lua
-- @runtime editor
local assetService = editor:GetService("AssetService")
local function removeOwnedFolderWithAssets(resType, folderName)
    if type(resType) ~= "string" or resType == "" then return end
    if type(folderName) ~= "string" or not folderName:match("%S") then return end
    assetService:RemoveUploadedFolderWithAssets(resType, folderName,
        function(success, result)
            if type(result) ~= "table" then
                print("未取得有效操作结果:", success, result)
                return
            end
            if not success then
                print("操作失败:", result.Operation, result.ErrorCode, result.ErrorMessage)
                return
            end
            print("删除目录及资源结果:", result.TagId, result.TagName, result.Removed, result.DeletedAssets)
        end)
end
-- 删除不可恢复。确认目录及其中全部资源均属于有权删除的范围后,
-- 由调用方显式调用 removeOwnedFolderWithAssets(resType, folderName)。
-- 本例不自动选取账号首个目录,也不自动执行删除。