Version: 2022.3
언어: 한국어

AssetImportContext.DependsOnCustomDependency

매뉴얼로 전환
public void DependsOnCustomDependency (string dependency);

파라미터

dependency Name of dependency. You can use any name you like, but because these names are global across all your Assets, it can be useful to use a naming convention (eg a path-based naming system as in the example below) to avoid clashes with other custom dependency names.

설명

Allows you to specify that an Asset has a custom dependency.

Use custom dependency if need to setup a dependency to something that can't be expressed as either an source asset dependency or artifact dependency.

using UnityEngine;
using UnityEditor.AssetImporters;
using UnityEditor.Experimental;
using UnityEngine.Assertions;
using UnityEditor;

class MySystem { public const string CustomDependencyName = "MyProject/Settings";

public static string GetSetting() { return "42"; }

public static void RegisterCustomDependency() { // You cannot register a custom dependency during the Asset Import process, so this method must be called before the Asset is imported. AssetDatabaseExperimental.RegisterCustomDependency(CustomDependencyName, Hash128.Compute(GetSetting())); } }

class SomeValue : ScriptableObject { public int value; }

[ScriptedImporter(1, "data", AllowCaching = true)] public class MyDataImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { ctx.DependsOnCustomDependency(MySystem.CustomDependencyName);

var someObj = ScriptableObject.CreateInstance<SomeValue>();

var setting = MySystem.GetSetting(); if (setting == "42") someObj.value = 100; else someObj.value = -1;

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