ProjectDDD/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs
2025-08-01 17:30:36 +09:00

111 lines
3.4 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(PathConstants.RawSpritesPathUpper))
{
if (upperPath.Contains(PathConstants.RawOnlyAtlasPathUpper))
{
AssetPostprocessorSprite.OnPreprocessTextureOnlyAtlas(importer);
}
else if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
{
AssetPostprocessorSprite.OnPreprocessTexture(importer);
}
else
{
AssetPostprocessorSprite.OnPreprocessTextureForUi(importer);
}
}
else if (upperPath.Contains(PathConstants.RawEnvironmentsPathUpper))
{
AssetPostprocessorEnvironment.OnPreprocessTexture(importer);
}
}
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deleteAssets, string[] movedAssets,
string[] movedFromAssetPaths)
{
for (int i = 0; i < movedAssets.Length; i++)
{
string fromPath = movedFromAssetPaths[i];
string toPath = movedAssets[i];
var upperPath = toPath.ToUpper();
// 특정 폴더일 때만 작동
if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
{
if (AssetDatabase.LoadAssetAtPath<Sprite>(toPath) == null)
{
Debug.Log($"에셋 이동 감지: {fromPath} → {toPath}");
// 여기서 임포트 강제 재실행
AssetDatabase.ImportAsset(toPath, ImportAssetOptions.ForceUpdate);
}
}
}
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();
AssetPostprocessorEnvironment.BuildTarget();
}
private static void PostRemove(string path, string movePath = "")
{
try
{
AssetPostprocessorSprite.OnRemove(path, movePath);
AssetPostprocessorEnvironment.OnRemove(path);
}
catch (System.Exception e)
{
Debug.LogError("Can't remove " + path + "\n" + e);
}
}
private static void PostAdd(string path)
{
try
{
AssetPostprocessorSprite.OnAdd(path);
AssetPostprocessorEnvironment.OnAdd(path);
}
catch (System.Exception e)
{
Debug.LogError("Can't import " + path + "\n" + e);
}
}
}
}
#endif