/// <summary>
 /// 创建AssetInfo
 /// </summary>
 /// <returns></returns>
 public static AssetInfo CreatAssetInfo(UnityEngine.Object asset)
 {
     return(new AssetInfo(asset.GetAssetModNameEditor(), asset.GetAssetNameEditor(),
                          ModsEditor.GetModId(asset.GetAssetModNameEditor()),
                          AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset)), asset.GetType()));
 }
예제 #2
0
 /// <summary>
 /// 获得资源所属Mod的Guid
 /// </summary>
 public static string GetModIdEditor <T>(this T asset) where T : UnityEngine.Object
 {
     return(ModsEditor.GetModId(asset.GetAssetModNameEditor()));
 }
 static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetsPaths)
 {
     repeat += 1;
     if (repeat > 100)
     {
         return;
     }
     //先处理导入的资源
     for (int i = 0; i < importedAssets.Length; i++)
     {
         var asset   = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(importedAssets[i]);
         var ModName = ModsEditor.GetModNameByPath(importedAssets[i]);
         //如果该资源不属于任何一个Mod或者是文件夹,无视
         if (ModName == null || AssetDatabase.IsValidFolder(importedAssets[i]))
         {
             continue;
         }
         ImportAsset(ModName, asset);
     }
     //再处理删除的资源
     for (int i = 0; i < deletedAssets.Length; i++)
     {
         var ModName = ModsEditor.GetModNameByPath(deletedAssets[i]);
         //如果该资源不属于任何一个Mod或者是文件夹,无视
         if (ModName == null || AssetDatabase.IsValidFolder(deletedAssets[i]))
         {
             continue;
         }
         var AssetName = ModsEditor.GetAssetNameByPath(deletedAssets[i]);
         DeleteAsset(ModName, AssetName);
     }
     //最后处理移动的资源
     for (int i = 0; i < movedAssets.Length; i++)
     {
         var asset     = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(movedAssets[i]);
         var FromMod   = ModsEditor.GetModNameByPath(movedFromAssetsPaths[i]);
         var ToMod     = ModsEditor.GetModNameByPath(movedAssets[i]);
         var assetName = asset.GetAssetNameEditor();
         //如果没有移动到另一个Mod或移动的是文件夹,无视(都为null,即并非Mod之间的资源移动,也无视)
         if (FromMod == ToMod || AssetDatabase.IsValidFolder(movedAssets[i]))
         {
             continue;
         }
         if (FromMod == null)
         {
             ImportAsset(ToMod, asset);
             continue;
         }
         if (ToMod == null)
         {
             AssetDatabase.RenameAsset(movedAssets[i], assetName);
             DeleteAsset(FromMod, assetName);
             continue;
         }
         var    FromModAI   = ModsEditor.GetAssetIndexer(FromMod);
         string newFullName = ToMod + "." + assetName;
         //将AssetInfo转移出来
         var Info = FromModAI[asset.name];
         FromModAI.Remove(asset.name);
         //更改Mod名
         asset.name  = assetName;
         newFullName = RenameAsset(newFullName, asset);
         //再将AssetInfo转移到新Mod
         Info.ModName   = ToMod;
         Info.ModId     = ModsEditor.GetModId(ToMod);
         Info.AssetName = AssetUtility.GetAssetName(newFullName);//如果发生了重名事件可以修改成新名称
         ModsEditor.GetAssetIndexer(ToMod).Add(newFullName, Info);
     }
     AssetDatabase.SaveAssets();
     AssetDatabase.Refresh();
 }