public void DependsOnArtifact (string path);
public void DependsOnArtifact (GUID guid);
public void DependsOnArtifact (Experimental.ArtifactKey key);

Parameters

pathThe path of the Asset whose artifact should be the dependency. Note: Although the dependency is the artifact (import result) which is stored in the library folder, this parameter is the path to the Asset in the Assets folder, and not a path to the artifact in the Library folder.
guidThe guid of the artifact dependency.
keyThe artifact key of the artifact dependency.

Description

Setup artifact dependency to an asset.

An artifact dependency is a dependency where an Asset depends on the import result (known as an artifact) of another Asset. If you change an Asset that has been marked as a dependency, all Assets which depend on it will also get reimported (after the dependency has been imported).

Note: If you specify an Asset as a dependency that doesn't exist or hasn't yet been imported, the dependency is still registered. It is registered as an un-imported Asset. When the Asset is later imported, all Assets which depend on it will also get reimported.

using UnityEngine;
using UnityEditor;
using UnityEditor.AssetImporters;

class TextureInfo : ScriptableObject { public int height; }

[ScriptedImporter(1, "cube")] public class CubeWithTextureImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { var assetDependency = "Assets/MyTexture.png";

ctx.DependsOnArtifact(assetDependency);

var texture = AssetDatabase.LoadAssetAtPath<Texture>(assetDependency);

if (texture != null) { var textureInfo = ScriptableObject.CreateInstance<TextureInfo>(); textureInfo.height = texture.height; ctx.AddObjectToAsset("TextureInfo", textureInfo); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961