AssetPostProcessors ui 처리
This commit is contained in:
parent
b836d2db17
commit
f01e00c1b4
@ -12,13 +12,12 @@ private void OnPreprocessTexture()
|
|||||||
var importer = assetImporter as TextureImporter;
|
var importer = assetImporter as TextureImporter;
|
||||||
|
|
||||||
var upperPath = importer.assetPath.ToUpper();
|
var upperPath = importer.assetPath.ToUpper();
|
||||||
|
|
||||||
// if (upperPath.Contains("ASSETS/RAW/Units/"))
|
if (upperPath.Contains(PathConstants.RawUiPathUpper))
|
||||||
// {
|
{
|
||||||
// AssetPostprocessorModel.OnPreprocessTexture(importer);
|
AssetPostprocessorSprite.OnPreprocessTextureForUi(importer);
|
||||||
// }
|
}
|
||||||
|
else if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
|
||||||
if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
|
|
||||||
{
|
{
|
||||||
AssetPostprocessorSprite.OnPreprocessTexture(importer);
|
AssetPostprocessorSprite.OnPreprocessTexture(importer);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,34 @@ public static void OnPreprocessTexture(TextureImporter importer)
|
|||||||
string path = importer.assetPath;
|
string path = importer.assetPath;
|
||||||
EditorApplication.delayCall += () => { TryApplyPivotAfterImport(path); };
|
EditorApplication.delayCall += () => { TryApplyPivotAfterImport(path); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void OnPreprocessTextureForUi(TextureImporter importer)
|
||||||
|
{
|
||||||
|
importer.textureType = TextureImporterType.Sprite;
|
||||||
|
importer.spriteImportMode = SpriteImportMode.Single;
|
||||||
|
|
||||||
|
// 기본 PPU (UI는 100 또는 1 고정 추천)
|
||||||
|
importer.spritePixelsPerUnit = 100f;
|
||||||
|
|
||||||
|
importer.sRGBTexture = true;
|
||||||
|
importer.isReadable = false;
|
||||||
|
importer.mipmapEnabled = false;
|
||||||
|
importer.streamingMipmaps = false;
|
||||||
|
importer.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
importer.filterMode = FilterMode.Bilinear;
|
||||||
|
|
||||||
|
importer.textureCompression = TextureImporterCompression.Uncompressed;
|
||||||
|
|
||||||
|
var textureSettings = new TextureImporterSettings();
|
||||||
|
importer.ReadTextureSettings(textureSettings);
|
||||||
|
textureSettings.spriteMeshType = SpriteMeshType.FullRect;
|
||||||
|
textureSettings.spriteExtrude = 2;
|
||||||
|
|
||||||
|
// ✅ UI는 항상 중앙 피벗 (또는 LeftTop 등 고정)
|
||||||
|
textureSettings.spriteAlignment = (int)SpriteAlignment.Center;
|
||||||
|
|
||||||
|
importer.SetTextureSettings(textureSettings);
|
||||||
|
}
|
||||||
|
|
||||||
private static void TryApplyPivotAfterImport(string path)
|
private static void TryApplyPivotAfterImport(string path)
|
||||||
{
|
{
|
||||||
@ -99,10 +127,14 @@ private static void TryApplyPivotAfterImport(string path)
|
|||||||
public static void OnRemove(string path, string movePath)
|
public static void OnRemove(string path, string movePath)
|
||||||
{
|
{
|
||||||
var upperPath = path.ToUpper();
|
var upperPath = path.ToUpper();
|
||||||
if (upperPath.Contains(PathConstants.RawSpritesPathUpper) == false ||
|
|
||||||
upperPath.Contains(ExtenstionConstants.PngExtensionUpper) == false) return;
|
|
||||||
|
|
||||||
if (TargetPaths.Contains(path) == false)
|
bool isValid = (upperPath.Contains(PathConstants.RawSpritesPathUpper) ||
|
||||||
|
upperPath.Contains(PathConstants.RawUiPathUpper))
|
||||||
|
&& upperPath.Contains(ExtenstionConstants.PngExtensionUpper);
|
||||||
|
|
||||||
|
if (!isValid) return;
|
||||||
|
|
||||||
|
if (!TargetPaths.Contains(path))
|
||||||
{
|
{
|
||||||
TargetPaths.Add(path);
|
TargetPaths.Add(path);
|
||||||
}
|
}
|
||||||
@ -111,10 +143,14 @@ public static void OnRemove(string path, string movePath)
|
|||||||
public static void OnAdd(string path)
|
public static void OnAdd(string path)
|
||||||
{
|
{
|
||||||
var upperPath = path.ToUpper();
|
var upperPath = path.ToUpper();
|
||||||
if (upperPath.Contains(PathConstants.RawSpritesPathUpper) == false ||
|
|
||||||
upperPath.Contains(ExtenstionConstants.PngExtensionUpper) == false) return;
|
|
||||||
|
|
||||||
if (TargetPaths.Contains(path) == false)
|
bool isValid = (upperPath.Contains(PathConstants.RawSpritesPathUpper) ||
|
||||||
|
upperPath.Contains(PathConstants.RawUiPathUpper))
|
||||||
|
&& upperPath.Contains(ExtenstionConstants.PngExtensionUpper);
|
||||||
|
|
||||||
|
if (!isValid) return;
|
||||||
|
|
||||||
|
if (!TargetPaths.Contains(path))
|
||||||
{
|
{
|
||||||
TargetPaths.Add(path);
|
TargetPaths.Add(path);
|
||||||
}
|
}
|
||||||
@ -143,7 +179,9 @@ public static void CreateAtlas(string path, string destPath)
|
|||||||
var maxSize = sprite.rect.size.x > sprite.rect.size.y ? sprite.rect.size.x : sprite.rect.size.y;
|
var maxSize = sprite.rect.size.x > sprite.rect.size.y ? sprite.rect.size.x : sprite.rect.size.y;
|
||||||
if (maxSize > 1024)
|
if (maxSize > 1024)
|
||||||
{
|
{
|
||||||
CreateSingleAtlas(filePath, path.Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) + $"_{fileName}{ExtenstionConstants.SpriteAtlasExtenstionLower}");
|
CreateSingleAtlas(filePath,
|
||||||
|
path.Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) +
|
||||||
|
$"_{fileName}{ExtenstionConstants.SpriteAtlasExtenstionLower}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +310,9 @@ public static void BuildTarget()
|
|||||||
{
|
{
|
||||||
foreach (var path in TargetPaths)
|
foreach (var path in TargetPaths)
|
||||||
{
|
{
|
||||||
CreateAtlas(Utils.FolderPath(path), Utils.FolderPath(path).Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) + ExtenstionConstants.SpriteAtlasExtenstionLower);
|
CreateAtlas(Utils.FolderPath(path),
|
||||||
|
Utils.FolderPath(path).Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) +
|
||||||
|
ExtenstionConstants.SpriteAtlasExtenstionLower);
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPaths.Clear();
|
TargetPaths.Clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user