Конструктор CollectImportedDependenciesAttribute
Declaration
public CollectImportedDependenciesAttribute(Type importerType, uint version);Параметры
| Параметр | Описание |
|---|---|
| importerType | Тип импортера, для которого геттер вызван AssetDatabase. |
| версия | Версия импортированного геттера зависимостей. |
Описание
Используйте атрибут 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 обратные вызова: ModelImporter, TextureImporter, AudioImporter, и SpeedTreeImporter.