using UnityEngine; using UnityEditor; /// /// 自動在 Play Mode 中偵測到 PageController 時掛載截圖工具 /// 持續監控,不管什麼時候進入操作員選單都會自動啟用 /// [InitializeOnLoad] public static class OperatorScreenshotLoader { static OperatorScreenshotLoader() { EditorApplication.playModeStateChanged += OnPlayModeChanged; } private static void OnPlayModeChanged(PlayModeStateChange state) { if (state == PlayModeStateChange.EnteredPlayMode) { // Play Mode 中持續監控 EditorApplication.update += CheckForPageController; } else if (state == PlayModeStateChange.ExitingPlayMode) { EditorApplication.update -= CheckForPageController; } } private static void CheckForPageController() { // 確認還在 Play Mode if (!EditorApplication.isPlaying) { EditorApplication.update -= CheckForPageController; return; } // 如果已經有截圖工具就不用再找 if (Object.FindObjectOfType() != null) return; // 找 PageController(可能在任何時候出現) var pc = Object.FindObjectOfType(); if (pc != null) { var go = new GameObject("ScreenshotTool"); go.AddComponent(); Debug.Log("📸 截圖工具已自動載入"); } } }