ProjectDDD/Assets/_Datas/02.Scripts/AssetPostprocessors/AssetPostProcessors.cs
2025-07-04 16:21:11 +09:00

79 lines
2.1 KiB
C#

#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace DDD
{
public class AssetPostProcessors : AssetPostprocessor
{
private void OnPreprocessTexture()
{
var importer = assetImporter as TextureImporter;
var upperPath = importer.assetPath.ToUpper();
// if (upperPath.Contains("ASSETS/RAW/Units/"))
// {
// AssetPostprocessorModel.OnPreprocessTexture(importer);
// }
if (upperPath.Contains("ASSETS/_DATAS/RAW/SPRITES/"))
{
AssetPostprocessorSprite.OnPreprocessTexture(importer);
}
}
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deleteAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (var path in deleteAssets)
{
PostRemove(path);
}
var index = 0;
foreach (var path in movedFromAssetPaths)
{
PostRemove(path, movedAssets[index]);
++index;
}
foreach (var path in movedAssets)
{
PostAdd(path);
}
foreach (var path in importedAssets)
{
PostAdd(path);
}
AssetPostprocessorSprite.BuildTarget();
AssetPostprocessorSprite.BuildTarget();
}
private static void PostRemove(string path, string movePath = "")
{
try
{
AssetPostprocessorSprite.OnRemove(path, movePath);
}
catch (System.Exception e)
{
Debug.LogError("Can't remove " + path + "\n" + e);
}
}
private static void PostAdd(string path)
{
try
{
AssetPostprocessorSprite.OnAdd(path);
}
catch (System.Exception e)
{
Debug.LogError("Can't import " + path + "\n" + e);
}
}
}
}
#endif