using System; using System.Collections.Generic; using System.IO; using System.Linq; using DevilLink2.UI; using UnityEditor; using UnityEngine; using UnityEngine.UI; namespace DevilLink2.Editor { // Editor-only transient visual copy: never opens a real screen or invokes a business callback. [InitializeOnLoad] public static class PopupRenderCompare { private const string Menu="Tools/Devil Link 2/Diagnostics/Popup Render Compare/"; private static GameObject overlay;private static RectTransform card;private static PopupAnimationController motion; private static CanvasGroup gate;private static bool native,shown,moving,staticMode; private static float started,from;private static int serial; private static readonly List owned=new List(); private static readonly List manifest=new List(); static PopupRenderCompare(){EditorApplication.playModeStateChanged+=State;AssemblyReloadEvents.beforeAssemblyReload+=Clear;} [MenuItem(Menu+"Original Rendering")] private static void Original(){native=false;Clear();Debug.Log("Render comparison A selected. Open Test Popup to run.");} [MenuItem(Menu+"Native Image Rendering")] private static void Native(){native=true;Clear();Debug.Log("Render comparison B selected. Open Test Popup to run.");} [MenuItem(Menu+"Open Test Popup")] private static void Open() { if(!Application.isPlaying){Debug.LogWarning("Requires Main Play Mode. Real save data is not touched by this tool.");return;} staticMode=true; if(shown)return; try {if(!overlay && !Build())return;}catch(Exception error){Clear();Debug.LogException(error);return;} shown=true;from=moving?motion.CurrentOffset:12;gate.alpha=1;motion.ResetVisual();overlay.SetActive(true); moving=!staticMode;started=Time.realtimeSinceStartup;gate.interactable=staticMode;gate.blocksRaycasts=true; } [MenuItem(Menu+"Close Test Popup")] private static void Close() { if(!overlay||!shown)return;shown=false;from=motion.CurrentOffset;started=Time.realtimeSinceStartup;moving=!staticMode; gate.interactable=false;if(staticMode)Finish(); } [MenuItem(Menu+"Static No Motion")] private static void Static(){staticMode=true;if(overlay)Finish();} [MenuItem(Menu+"Motion Retired - Static Only")] private static void Animated(){staticMode=true;Debug.Log("Popup motion retired; static rendering comparison only.");} [MenuItem(Menu+"Remove Test Popup")] private static void Clear() { moving=shown=false;if(overlay)UnityEngine.Object.DestroyImmediate(overlay);overlay=null;card=null;motion=null;gate=null; foreach(var item in owned)if(item)UnityEngine.Object.DestroyImmediate(item);owned.Clear(); } private static void State(PlayModeStateChange state){if(state==PlayModeStateChange.ExitingPlayMode)Clear();} private static bool Build() { var wheel=UnityEngine.Object.FindFirstObjectByType(FindObjectsInactive.Include); if(!wheel){Debug.LogWarning("Cached LuckyWheelScreen not found. Initialize Main first.");return false;} var source=wheel.transform.Find("Card") as RectTransform;if(!source){Debug.LogWarning("Wheel Card not found; no hierarchy changed.");return false;} if(wheel.IsSpinning){Debug.LogWarning("Wait until the real wheel is idle before creating a visual test copy.");return false;} var originalRoot=(RectTransform)wheel.transform; var root=new GameObject("DiagnosticPopupRenderCompare",typeof(RectTransform));overlay=root; root.SetActive(false);var rect=(RectTransform)root.transform;rect.SetParent(wheel.transform.parent,false); rect.anchorMin=originalRoot.anchorMin;rect.anchorMax=originalRoot.anchorMax;rect.pivot=originalRoot.pivot;rect.sizeDelta=originalRoot.sizeDelta;rect.anchoredPosition=originalRoot.anchoredPosition; root.hideFlags=HideFlags.DontSave;var shade=root.AddComponent();shade.color=wheel.GetComponent().color;shade.raycastTarget=true; gate=root.AddComponent();gate.alpha=1; card=UnityEngine.Object.Instantiate(source,rect,false);card.name="TestVisualRoot"; // Disable layout/business updates before activation, preserving only visual and input primitives. foreach(var script in card.GetComponentsInChildren(true)){ bool keep=script is Graphic || script is BaseMeshEffect || script is Selectable || script is ScrollRect; if(!keep)script.enabled=false; } foreach(var button in card.GetComponentsInChildren