Version: 2023.2

AssetDatabase.GetImporterType

切换到手册
public static Type GetImporterType (GUID guid);

参数

guid GUID of the asset to get the importer type from.

描述

Returns the type of importer associated with an asset without loading the asset.

This method allows you to determine which importer is associated with an asset. This method is more efficient than AssetImporter.GetAtPath, which also loads the object. If you need to check a large number of asset importers at once, you should use the batch version of this method AssetDatabase.GetImporterTypes.

using UnityEngine;
using UnityEditor;

public class AssetDatabaseExamples { [MenuItem("AssetDatabase/GetMatchingAssetType")] public static void GetMatchingAssetType() { var matchingAssets = AssetDatabase.FindAssets("Powerup"); var matchingAssetGuid = new GUID(matchingAssets[0]); Debug.Log($"Importer type: {AssetDatabase.GetImporterType(matchingAssetGuid)}"); } }

public static Type GetImporterType (string assetPath);

参数

assetPath Path of asset to get importer Type from.

描述

Returns the type of the importer associated with an asset without loading the asset.

The asset path you provide should be relative to the project folder root. For example, "Assets/MyTextures/hello.png". This method allows you to determine which importer is associated with an asset. This method is more efficient than AssetImporter.GetAtPath, which also loads the object. If you need to check a large number of asset importers at once, you should use the batch version of this method AssetDatabase.GetImporterTypes.

using UnityEngine;
using UnityEditor;

public class AssetDatabaseExamples { [MenuItem("AssetDatabase/GetImporterTypeOfSelectedObject")] public static void GetImporterTypeOfSelectedObject() { var selectedObject = Selection.activeObject; var objectPath = AssetDatabase.GetAssetPath(selectedObject); Debug.Log($"Importer type: {AssetDatabase.GetImporterType(objectPath)}"); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961