Experimental: this API is experimental and might be changed or removed in the future.

CollectImportedDependenciesAttributeConstructor

切换到手册
public CollectImportedDependenciesAttribute (Type importerType, uint version);

参数

importerType AssetDatabase 为其调用 getter 的导入器类型。
version导入依赖关系 getter 的版本。

描述

使用 CollectImportedDependencies 属性可为导入的依赖关系声明 getter。

建议每次脚本更改时都递增回调的版本号。这会强制重新导入用较低版本号导入的资源。

此示例说明如何声明由 ModelImporter 导入的两个预制件之间的依赖关系以及如何在 AssetPostprocessor 中使用这两个预制件。

using UnityEditor;
using UnityEditor.Experimental.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 回调支持原生导入器类型:ModelImporterTextureImporterAudioImporterSpeedTreeImporter