using UnityEditor; using UnityEngine; namespace Unity.Pipeline.Editor { /// /// Inspectable configuration and control surface for the live editor pipeline server. This is a /// settings asset, NOT the server's owner — owns the server /// instance (a static owner survives domain reloads cleanly, whereas a ScriptableObject's /// lifetime does not track the server across editor events). The owner reads this asset's config /// when starting; the custom inspector drives Start/Stop through the owner and shows live status. /// /// The asset is optional: without it the owner uses the defaults below. "Pipeline/Settings" /// creates it on demand. /// public class EditorPipelineManager : ScriptableObject { [Tooltip("HTTP port for the editor server. 0 = auto-assign from the 7800-7849 range. Applies on next start.")] [SerializeField] private ushort m_Port = 0; [Tooltip("Start the server automatically when the editor loads. Applies on next editor load.")] [SerializeField] private bool m_AutoStart = true; [Tooltip("Self-heal: if the HTTP listener dies without a Stop(), re-open it on a timer. " + "Keeps auto-tick on so the editor keeps ticking while unfocused (required for the watchdog).")] [SerializeField] private bool m_WatchdogEnabled = true; [Tooltip("How often the watchdog checks the listener, between 1 and 60 seconds.")] [SerializeField] private int m_WatchdogIntervalSeconds = 5; [Tooltip("Log every command request/response (raw JSON) handled by the editor server to " + "/Logs/pipeline.log. Editor only; applies live.")] [SerializeField] private bool m_LogRequestsResponses = false; public int Port => m_Port; public bool AutoStart => m_AutoStart; public bool WatchdogEnabled => m_WatchdogEnabled; public int WatchdogIntervalSeconds => m_WatchdogIntervalSeconds; public bool LogRequestsResponses => m_LogRequestsResponses; /// Whether the live server (owned by PipelineServerStartup) is actually running. public bool IsServerRunning => PipelineServerStartup.Server != null && PipelineServerStartup.Server.IsRunning; /// The port the live server is actually listening on, or 0 when stopped. public int ActualPort => PipelineServerStartup.Server?.Port ?? 0; /// Start the live server (delegates to the static owner, which reads this config). public void StartServer() => PipelineServerStartup.EnsureServerStarted(); /// Stop the live server. public void StopServer() => PipelineServerStartup.StopServer(); /// Restart the live server. public void RestartServer() => PipelineServerStartup.RestartServer(); /// /// Load the single settings asset if one exists, otherwise null (the owner falls back to /// defaults). No caching — assets are cheap to look up and this is only read at start/inspect. /// public static EditorPipelineManager Load() { var guids = AssetDatabase.FindAssets("t:EditorPipelineManager"); if (guids.Length == 0) return null; return AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath(guids[0])); } private void OnValidate() { m_WatchdogIntervalSeconds = Mathf.Clamp(m_WatchdogIntervalSeconds, 1, 60); } } }