115 lines
3.2 KiB
C#
115 lines
3.2 KiB
C#
using UnityEditor;
|
|
using UnityTcp.Editor.Helpers;
|
|
|
|
namespace UnityTcp.Editor.Windows
|
|
{
|
|
/// <summary>
|
|
/// Menu items for quick Codely bridge operations
|
|
/// </summary>
|
|
public static class TcpBridgeMenuItems
|
|
{
|
|
public static void StartServer()
|
|
{
|
|
if (!UnityTcpBridge.IsRunning)
|
|
{
|
|
UnityTcpBridge.Start();
|
|
TcpLog.Info("Codely Bridge started via menu");
|
|
}
|
|
else
|
|
{
|
|
TcpLog.Info("Codely Bridge is already running");
|
|
}
|
|
}
|
|
|
|
public static bool StartServerValidate()
|
|
{
|
|
return !UnityTcpBridge.IsRunning;
|
|
}
|
|
|
|
public static void StopServer()
|
|
{
|
|
if (UnityTcpBridge.IsRunning)
|
|
{
|
|
UnityTcpBridge.Stop(true); // Pass true to indicate manual stop
|
|
TcpLog.Info("Codely Bridge manually stopped via menu");
|
|
}
|
|
else
|
|
{
|
|
TcpLog.Info("Codely Bridge is not running");
|
|
}
|
|
}
|
|
|
|
public static bool StopServerValidate()
|
|
{
|
|
return UnityTcpBridge.IsRunning;
|
|
}
|
|
|
|
public static void RestartServer()
|
|
{
|
|
UnityTcpBridge.Stop();
|
|
System.Threading.Thread.Sleep(100);
|
|
UnityTcpBridge.Start();
|
|
TcpLog.Info("Codely Bridge restarted via menu");
|
|
}
|
|
|
|
public static void ShowServerStatus()
|
|
{
|
|
bool isRunning = UnityTcpBridge.IsRunning;
|
|
int port = UnityTcpBridge.GetCurrentPort();
|
|
|
|
string message = isRunning
|
|
? $"Codely Bridge is RUNNING on port {port}\nConnect to: localhost:{port}"
|
|
: "Codely Bridge is STOPPED";
|
|
|
|
EditorUtility.DisplayDialog("Codely Bridge Status", message, "OK");
|
|
}
|
|
|
|
public static void DiscoverNewPort()
|
|
{
|
|
try
|
|
{
|
|
int newPort = PortManager.DiscoverNewPort();
|
|
string message = $"New port discovered: {newPort}\n\nRestart the Codely Bridge to use the new port.";
|
|
|
|
bool restart = EditorUtility.DisplayDialog(
|
|
"New Port Discovered",
|
|
message,
|
|
"Restart Now",
|
|
"Later"
|
|
);
|
|
|
|
if (restart)
|
|
{
|
|
RestartServer();
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
EditorUtility.DisplayDialog("Port Discovery Failed", ex.Message, "OK");
|
|
}
|
|
}
|
|
|
|
public static void EnableDebugLogging()
|
|
{
|
|
EditorPrefs.SetBool("UnityTcp.DebugLogs", true);
|
|
TcpLog.Info("Debug logging enabled");
|
|
}
|
|
|
|
public static bool EnableDebugLoggingValidate()
|
|
{
|
|
return !EditorPrefs.GetBool("UnityTcp.DebugLogs", false);
|
|
}
|
|
|
|
public static void DisableDebugLogging()
|
|
{
|
|
EditorPrefs.SetBool("UnityTcp.DebugLogs", false);
|
|
TcpLog.Info("Debug logging disabled");
|
|
}
|
|
|
|
public static bool DisableDebugLoggingValidate()
|
|
{
|
|
return EditorPrefs.GetBool("UnityTcp.DebugLogs", false);
|
|
}
|
|
}
|
|
}
|