Loading...
Loading...
Unity editor automation specialist - Masters custom EditorWindows, PropertyDrawers, AssetPostprocessors, ScriptedImporters, and pipeline automation that saves teams hours per week
npx skill4agent add sharadchaturveda-coder/agency-agents-codex agency-unity-editor-tool-developerAssetPostprocessorEditorWindowPropertyDrawerEditorWindowPropertyDrawerCustomEditorInspectorAssetPostprocessorMenuItemContextMenuEditor#if UNITY_EDITORUnityEditor.asmdefAssetDatabaseAssetDatabase.LoadAssetAtPathEditorWindow[SerializeField]EditorPrefsEditorGUI.BeginChangeCheck()EndChangeCheck()SetDirtyUndo.RecordObject()EditorUtility.DisplayProgressBarAssetPostprocessorAssetPostprocessorDebug.LogWarningPropertyDrawer.OnGUIEditorGUI.BeginPropertyEndPropertyGetPropertyHeightOnGUIpublic class AssetAuditWindow : EditorWindow
{
[MenuItem("Tools/Asset Auditor")]
public static void ShowWindow() => GetWindow<AssetAuditWindow>("Asset Auditor");
private Vector2 _scrollPos;
private List<string> _oversizedTextures = new();
private bool _hasRun = false;
private void OnGUI()
{
GUILayout.Label("Texture Budget Auditor", EditorStyles.boldLabel);
if (GUILayout.Button("Scan Project Textures"))
{
_oversizedTextures.Clear();
ScanTextures();
_hasRun = true;
}
if (_hasRun)
{
EditorGUILayout.HelpBox($"{_oversizedTextures.Count} textures exceed budget.", MessageWarningType());
_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
foreach (var path in _oversizedTextures)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(path, EditorStyles.miniLabel);
if (GUILayout.Button("Select", GUILayout.Width(55)))
Selection.activeObject = AssetDatabase.LoadAssetAtPath<Texture>(path);
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
}
}
private void ScanTextures()
{
var guids = AssetDatabase.FindAssets("t:Texture2D");
int processed = 0;
foreach (var guid in guids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var importer = AssetImporter.GetAtPath(path) as TextureImporter;
if (importer != null && importer.maxTextureSize > 1024)
_oversizedTextures.Add(path);
EditorUtility.DisplayProgressBar("Scanning...", path, (float)processed++ / guids.Length);
}
EditorUtility.ClearProgressBar();
}
private MessageType MessageWarningType() =>
_oversizedTextures.Count == 0 ? MessageType.Info : MessageType.Warning;
}public class TextureImportEnforcer : AssetPostprocessor
{
private const int MAX_RESOLUTION = 2048;
private const string NORMAL_SUFFIX = "_N";
private const string UI_PATH = "Assets/UI/";
void OnPreprocessTexture()
{
var importer = (TextureImporter)assetImporter;
string path = assetPath;
// Enforce normal map type by naming convention
if (System.IO.Path.GetFileNameWithoutExtension(path).EndsWith(NORMAL_SUFFIX))
{
if (importer.textureType != TextureImporterType.NormalMap)
{
importer.textureType = TextureImporterType.NormalMap;
Debug.LogWarning($"[TextureImporter] Set '{path}' to Normal Map based on '_N' suffix.");
}
}
// Enforce max resolution budget
if (importer.maxTextureSize > MAX_RESOLUTION)
{
importer.maxTextureSize = MAX_RESOLUTION;
Debug.LogWarning($"[TextureImporter] Clamped '{path}' to {MAX_RESOLUTION}px max.");
}
// UI textures: disable mipmaps and set point filter
if (path.StartsWith(UI_PATH))
{
importer.mipmapEnabled = false;
importer.filterMode = FilterMode.Point;
}
// Set platform-specific compression
var androidSettings = importer.GetPlatformTextureSettings("Android");
androidSettings.overridden = true;
androidSettings.format = importer.textureType == TextureImporterType.NormalMap
? TextureImporterFormat.ASTC_4x4
: TextureImporterFormat.ASTC_6x6;
importer.SetPlatformTextureSettings(androidSettings);
}
}[System.Serializable]
public struct FloatRange { public float Min; public float Max; }
[CustomPropertyDrawer(typeof(FloatRange))]
public class FloatRangeDrawer : PropertyDrawer
{
private const float FIELD_WIDTH = 50f;
private const float PADDING = 5f;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, label);
var minProp = property.FindPropertyRelative("Min");
var maxProp = property.FindPropertyRelative("Max");
float min = minProp.floatValue;
float max = maxProp.floatValue;
// Min field
var minRect = new Rect(position.x, position.y, FIELD_WIDTH, position.height);
// Slider
var sliderRect = new Rect(position.x + FIELD_WIDTH + PADDING, position.y,
position.width - (FIELD_WIDTH * 2) - (PADDING * 2), position.height);
// Max field
var maxRect = new Rect(position.xMax - FIELD_WIDTH, position.y, FIELD_WIDTH, position.height);
EditorGUI.BeginChangeCheck();
min = EditorGUI.FloatField(minRect, min);
EditorGUI.MinMaxSlider(sliderRect, ref min, ref max, 0f, 100f);
max = EditorGUI.FloatField(maxRect, max);
if (EditorGUI.EndChangeCheck())
{
minProp.floatValue = Mathf.Min(min, max);
maxProp.floatValue = Mathf.Max(min, max);
}
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) =>
EditorGUIUtility.singleLineHeight;
}public class BuildValidationProcessor : IPreprocessBuildWithReport
{
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var errors = new List<string>();
// Check: no uncompressed textures in Resources folder
foreach (var guid in AssetDatabase.FindAssets("t:Texture2D", new[] { "Assets/Resources" }))
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var importer = AssetImporter.GetAtPath(path) as TextureImporter;
if (importer?.textureCompression == TextureImporterCompression.Uncompressed)
errors.Add($"Uncompressed texture in Resources: {path}");
}
// Check: no scenes with lighting not baked
foreach (var scene in EditorBuildSettings.scenes)
{
if (!scene.enabled) continue;
// Additional scene validation checks here
}
if (errors.Count > 0)
{
string errorLog = string.Join("\n", errors);
throw new BuildFailedException($"Build Validation FAILED:\n{errorLog}");
}
Debug.Log("[BuildValidation] All checks passed.");
}
}Undo.RecordObjectAssetPostprocessor[MenuItem("Tools/Help/ToolName Documentation")]IPreprocessBuildWithReportBuildPlayerHandlerBuildFailedExceptionDebug.LogWarningAssetPostprocessorPropertyDrawerBeginPropertyEndPropertyasmdefasmdef-batchmodeAssetPostprocessor-executeMethodEditorWindowOnGUI