using Minigames.TrashMaze.Objects; using UnityEditor; using UnityEngine; namespace Editor.CustomEditorsAndDrawers { [CustomEditor(typeof(RevealableObject))] public class RevealableObjectEditor : UnityEditor.Editor { private RenderTexture _cachedStampTexture; private Texture2D _previewTexture; public override void OnInspectorGUI() { DrawDefaultInspector(); // Only show debug info in play mode if (!Application.isPlaying) { return; } EditorGUILayout.Space(10); EditorGUILayout.LabelField("Progressive Reveal Debug (Play Mode Only)", EditorStyles.boldLabel); EditorGUILayout.HelpBox("Shows the current stamp texture for Progressive reveal mode.", MessageType.Info); RevealableObject revealableObject = (RevealableObject)target; // Use reflection to get private _revealStampTexture field var field = typeof(RevealableObject).GetField("_revealStampTexture", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (field != null) { RenderTexture stampTexture = field.GetValue(revealableObject) as RenderTexture; if (stampTexture != null) { // Display stamp texture info EditorGUILayout.LabelField("Stamp Texture:", $"{stampTexture.width}x{stampTexture.height}"); // Show preview of stamp texture GUILayout.Label("Reveal Mask Preview (White = Revealed):"); // Create preview texture if needed if (_cachedStampTexture != stampTexture || _previewTexture == null) { _cachedStampTexture = stampTexture; if (_previewTexture != null) { DestroyImmediate(_previewTexture); } _previewTexture = new Texture2D(stampTexture.width, stampTexture.height, TextureFormat.R8, false); _previewTexture.filterMode = FilterMode.Point; } // Copy RenderTexture to Texture2D for preview RenderTexture.active = stampTexture; _previewTexture.ReadPixels(new Rect(0, 0, stampTexture.width, stampTexture.height), 0, 0); _previewTexture.Apply(); RenderTexture.active = null; // Display preview with fixed size float previewSize = 256f; float aspectRatio = (float)stampTexture.height / stampTexture.width; Rect previewRect = GUILayoutUtility.GetRect(previewSize, previewSize * aspectRatio); EditorGUI.DrawPreviewTexture(previewRect, _previewTexture, null, ScaleMode.ScaleToFit); // Auto-refresh in play mode if (Application.isPlaying) { Repaint(); } } else { EditorGUILayout.HelpBox("No stamp texture found. Make sure object is in Progressive reveal mode.", MessageType.Warning); } } else { EditorGUILayout.HelpBox("Could not access stamp texture via reflection.", MessageType.Error); } } private void OnDisable() { // Clean up preview texture if (_previewTexture != null) { DestroyImmediate(_previewTexture); _previewTexture = null; } } } }