texture stitcher (literally psd layers but im lazy)

This commit is contained in:
Lillith Rose 2026-01-25 17:58:41 -05:00
parent d8a57c3817
commit 2c3589b408
7 changed files with 249 additions and 0 deletions

View file

@ -0,0 +1,67 @@
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<TextureStitcherSettings>(
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<Texture2D>(path);
if (!tex) continue;
foreach (var stitcher in stitchers)
{
if (stitcher.textures.Contains(tex))
TextureStitcherEditor.GenerateStitchedTexture(stitcher);
}
}
}
}
}