Detect Asset Deletion, Modify In Unity Editor

这个博客探讨了Unity中如何在删除资产时执行自定义操作。`OnWillDeleteAsset` 方法被用于在删除资源之前进行检查,如果资源类型匹配特定条件,将调用外部库删除关联数据。此外,示例还展示了如何在创建资产时进行日志记录。这对于实现编辑器扩展和保护数据完整性至关重要。
摘要由CSDN通过智能技术生成

//   Detect Asset Deletion  /

  1. static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)

  2.         {

  3.             AssetDeleteResult finalResult = AssetDeleteResult.DidNotDelete;

  4.             if (!InternalEditorUtility.HasTeamLicense())

  5.                 return finalResult;

  6. ...

  1. using UnityEngine;

  2. using UnityEditor;

  3. public class Test : UnityEditor.AssetModificationProcessor

  4. {

  5.     static void OnWillCreateAsset(string assetName)

  6.     {

  7.         Debug.Log("OnWillCreateAsset is being called with the following asset: " + assetName + ".");

  8.     }

  9.     static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions opt)

  10.     {

  11.         Debug.Log("OnWillDeleteAsset");

  12.         Debug.Log(path);

  13.         return AssetDeleteResult.FailedDelete;

  14.     }

  15. }

  1.  static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions opt)

  2.     {

  3.         if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(MyType))

  4.         {

  5.             if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(AssetDatabase.LoadAssetAtPath<MyType>(path), out var guid, out long id))

  6.                 Lucene.DeleteDocument(guid);

  7.         }

  8.         return AssetDeleteResult.DidNotDelete;

  9.     }

///

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值