AssetDatabase.GetImplicitAssetBundleName

Unity · Версия 2020.3 LTS · Scripting · AssetDatabase

AssetDatabase.GetImplicitAssetBundleName

Объявление

public static string GetImplicitAssetBundleName(string assetPath);

Параметры

assetPath Путь актива.

Возвращает

string Возвращает имя AssetBundle, к которому принадлежит данный актив. Подробности смотрите в описании метода.

Описание

Возвращает имя AssetBundle, к которому принадлежит данный ресурс.

Если ресурс был явно назначен AssetBundle, возвращается это значение. Если актив не принадлежит AssetBundle, его родительские папки просматриваются до тех пор, пока не будет найдена папка, принадлежащая AssetBundle. Если папка, соответствующая этому условию, найдена, возвращается ее имя AssetBundle. Если ничего не найдено, возвращается пустая строка.

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
public class AssetDatabaseExamples : MonoBehaviour
{
    [MenuItem("AssetDatabase/Check Bundle Names")]
    static void CheckBundleNames()
    {
        var assetsWithIncorrectBundle = new List();
        var correctBundleName = "metaltexturebundle";
        //Check if any of the assets have an incorrect bundle set to them
        for (var i = 0; i < 10; i++)
        {
            var texturePath = $"Assets/Textures/Metal/Metal{i}.png";
            if(AssetDatabase.GetImplicitAssetBundleName(texturePath) != correctBundleName)
                assetsWithIncorrectBundle.Add(texturePath);
        }

        //If no such assets exist then return
        if (!assetsWithIncorrectBundle.Any())
            return;
        //If there are such assets then print them out
        var incorrectAssetNames = "";
        foreach (var asset in assetsWithIncorrectBundle)
        {
            incorrectAssetNames += $"\"{asset}\" ";
        }
        Debug.LogWarning($"Assets with an incorrect Asset Bundle {incorrectAssetNames}");
    }
}

Обновлено 17 ноября 2026 г.