← Files UnityARCHIVED FILE
skills/2d-pixel-perfect/references/sprite-settings.cs
1.33 KB · Oct 3, 2026 · 06:34 UTC
// PixelPerfect Skill — Sprite Import Settings (Editor-only)
// ----------------------------------------------------------
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace PixelPerfect.Editor
{
public static class SpriteImportUtility
{
public static TextureImporter GetImporter(Sprite sprite)
{
if (sprite == null) return null;
var path = AssetDatabase.GetAssetPath(sprite);
if (string.IsNullOrEmpty(path)) return null;
return AssetImporter.GetAtPath(path) as TextureImporter;
}
public static bool FixSpriteImportSettings(Sprite sprite, int targetPPU)
{
var importer = GetImporter(sprite);
if (importer == null) { Debug.LogWarning($"No importer for: {sprite?.name}"); return false; }
importer.filterMode = FilterMode.Point;
importer.mipmapEnabled = false;
importer.textureCompression = TextureImporterCompression.Uncompressed;
importer.spritePixelsPerUnit = targetPPU;
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(sprite), ImportAssetOptions.ForceUpdate);
return true;
}
// After batch-fixing multiple sprites, always flush with:
// AssetDatabase.SaveAssets();
// AssetDatabase.Refresh();
}
}
#endif
SHA-256: 6e154662f004b39bcf88bf1991b276305a8c55d50ab0883cf8b4ca1e4fb0d594