67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|