using UnityEditor; using UnityEngine; using System.Linq; namespace gay.lilyy.TextureAtlasGenerator { public class TextureAtlasAutoRegen : AssetPostprocessor { private const string MenuPath = "LillithRosePup/Import Regens/Texture Atlas"; private const string PrefKey = "TextureAtlasGenerator.AutoRegen"; [MenuItem(MenuPath)] private static void Toggle() { bool enabled = !EditorPrefs.GetBool(PrefKey, true); EditorPrefs.SetBool(PrefKey, enabled); Menu.SetChecked(MenuPath, enabled); } [MenuItem(MenuPath, true)] private static bool ToggleValidate() { Menu.SetChecked(MenuPath, EditorPrefs.GetBool(PrefKey, true)); return true; } private static bool IsEnabled() { return EditorPrefs.GetBool(PrefKey, true); } static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (!IsEnabled()) return; if (importedAssets.Length == 0) return; var atlases = AssetDatabase .FindAssets("t:TextureAtlasSettings") .Select(guid => AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath(guid))) .Where(s => s && s.textures != null && s.textures.Length > 0) .ToArray(); if (atlases.Length == 0) return; foreach (string path in importedAssets) { var tex = AssetDatabase.LoadAssetAtPath(path); if (!tex) continue; foreach (var atlas in atlases) { if (atlas.textures.Contains(tex)) TextureAtlasEditor.GenerateAtlas(atlas); } } } } }