Объявление
public CollectImportedDependenciesAttribute(Type importerType, uint version);Параметры
importerType | Тип импортера, для которого геттер вызывается AssetDatabase. |
version | Версия получателя импортированных зависимостей. |
Описание
Используйте атрибут CollectImportedDependencies, чтобы объявить геттеры для импортированных зависимостей.
Рекомендуется всегда увеличивать номер версии обратного вызова при каждом изменении сценария. Это приводит к повторному импорту ресурсов, импортированных с более низкими номерами версий.
В этом примере показано, как можно объявить зависимость между двумя префабами, импортированными с помощью ModelImporter, и использовать их в AssetPostprocessor.
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
public class ProceduralParentPostprocessor : AssetPostprocessor
{
private const string s_DependentPath = "Assets/ProceduralPrefab.fbx";
private const string s_DependencyPath = "Assets/DependencyPrefab.fbx";
[CollectImportedDependencies(typeof(ModelImporter), 1)]
public static string[] CollectImportedDependenciesForModelImporter(string assetPath)
{
if (assetPath.Equals(s_DependentPath))
return new[] { s_DependencyPath };
return null;
}
void OnPostprocessMeshHierarchy(GameObject root)
{
if (root.name == "ProceduralPrefabRoot")
{
// Add a new child game object
var go = AssetDatabase.LoadMainAssetAtPath(s_DependencyPath) as GameObject;
Object.Instantiate(go, root.transform, true);
}
}
}
Примечание. Этот атрибут поддерживает только собственные типы импортеров с AssetPostprocessor callbacks: ModelImporter, TextureImporter, AudioImporter, and SpeedTreeImporter.