using UnityEditor; using UnityEngine; using System.Linq; namespace gay.lilyy.TextureStitcher { public class TextureStitcherAutoRegen : AssetPostprocessor { private const string MenuPath = "LillithRosePup/Import Regens/Texture Stitcher"; private const string PrefKey = "TextureStitcher.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 stitchers = AssetDatabase .FindAssets("t:TextureStitcherSettings") .Select(guid => AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath(guid))) .Where(s => s && s.textures != null && s.textures.Length > 0) .ToArray(); if (stitchers.Length == 0) return; foreach (string path in importedAssets) { var tex = AssetDatabase.LoadAssetAtPath(path); if (!tex) continue; foreach (var stitcher in stitchers) { if (stitcher.textures.Contains(tex)) TextureStitcherEditor.GenerateStitchedTexture(stitcher); } } } } }