AssetDatabase.GetAvailableImporterTypes

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

AssetDatabase.GetAvailableImporterTypes

Объявление

public static Type[] GetAvailableImporterTypes(string path);

Параметры

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

Возвращает

Type[] Возвращает массив типов импортеров, которые могут обрабатывать указанный актив.

Описание

Получает типы импортеров, связанные с данным типом объекта.

using System;
using UnityEngine;
using UnityEditor;
using UnityEditor.AssetImporters;

public class AssetDatabaseExamples : MonoBehaviour
{
    [MenuItem("AssetDatabase/Available Importer Types for cube")]
    static void AvailableImporterTypeCube()
    {
        Type[] CubeTypes = AssetDatabase.GetAvailableImporterTypes("Assets/CompanionCube.cube");
        for (int i = 0; i < CubeTypes.Length; i++)
        {
            Debug.Log("Available Importer Type for cube: " + CubeTypes[i]);
        }
    }

    //This is Example Importer for cube
    [ScriptedImporter(1, "cube")]
    public class CubeImporter : ScriptedImporter
    {
        public float m_Scale = 1;
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            var position = new Vector3(0, 0, 0);
            cube.transform.position = position;
            cube.transform.localScale = new Vector3(m_Scale, m_Scale, m_Scale);
            // 'cube' is a a GameObject and will be automatically converted into a prefab
            ctx.AddObjectToAsset("main obj", cube);
            ctx.SetMainObject(cube);
            var material = new Material(Shader.Find("Standard"));
            material.color = Color.red;
            ctx.AddObjectToAsset("my Material", material);
            var tempMesh = new Mesh();
        }
    }
}

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