개발자용 멀티플레이 기능 추가
This commit is contained in:
176
Assets/Scripts/Editor/NetworkConnectionHelperEditor.cs
Normal file
176
Assets/Scripts/Editor/NetworkConnectionHelperEditor.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Unity.Netcode;
|
||||
|
||||
namespace Northbound.Editor
|
||||
{
|
||||
[CustomEditor(typeof(NetworkConnectionHelper))]
|
||||
public class NetworkConnectionHelperEditor : UnityEditor.Editor
|
||||
{
|
||||
private NetworkConnectionHelper _helper;
|
||||
private GUIStyle _statusStyle;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_helper = (NetworkConnectionHelper)target;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
_statusStyle = new GUIStyle(EditorStyles.boldLabel);
|
||||
_statusStyle.alignment = TextAnchor.MiddleCenter;
|
||||
_statusStyle.fontSize = 12;
|
||||
|
||||
DrawDefaultInspector();
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
DrawConnectionControls();
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
DrawStatus();
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
DrawQuickActions();
|
||||
}
|
||||
|
||||
private void DrawConnectionControls()
|
||||
{
|
||||
EditorGUILayout.LabelField("Network Controls", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginDisabledGroup(IsConnected());
|
||||
|
||||
if (GUILayout.Button("Start Host", GUILayout.Height(30)))
|
||||
{
|
||||
_helper.StartHost();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Start Server", GUILayout.Height(30)))
|
||||
{
|
||||
_helper.StartServer();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Start Client", GUILayout.Height(30)))
|
||||
{
|
||||
_helper.StartClient();
|
||||
}
|
||||
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUI.BeginDisabledGroup(!IsConnected());
|
||||
|
||||
if (GUILayout.Button("Disconnect", GUILayout.Height(30)))
|
||||
{
|
||||
_helper.Disconnect();
|
||||
}
|
||||
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
private void DrawStatus()
|
||||
{
|
||||
EditorGUILayout.LabelField("Status", EditorStyles.boldLabel);
|
||||
|
||||
string status = GetDetailedStatus();
|
||||
Color bgColor = GetStatusColor();
|
||||
|
||||
var oldBgColor = GUI.backgroundColor;
|
||||
GUI.backgroundColor = bgColor;
|
||||
|
||||
EditorGUILayout.LabelField(status, _statusStyle, GUILayout.Height(25));
|
||||
|
||||
GUI.backgroundColor = oldBgColor;
|
||||
|
||||
if (NetworkManager.Singleton != null && IsConnected())
|
||||
{
|
||||
DrawNetworkInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawNetworkInfo()
|
||||
{
|
||||
EditorGUILayout.LabelField("Network Information", EditorStyles.boldLabel);
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
|
||||
{
|
||||
if (NetworkManager.Singleton.IsHost)
|
||||
{
|
||||
EditorGUILayout.LabelField($"Mode: Host");
|
||||
}
|
||||
else if (NetworkManager.Singleton.IsServer)
|
||||
{
|
||||
EditorGUILayout.LabelField($"Mode: Server");
|
||||
}
|
||||
else if (NetworkManager.Singleton.IsClient)
|
||||
{
|
||||
EditorGUILayout.LabelField($"Mode: Client");
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField($"Connected Clients: {NetworkManager.Singleton.ConnectedClients.Count}");
|
||||
EditorGUILayout.LabelField($"Local Client ID: {NetworkManager.Singleton.LocalClientId}");
|
||||
|
||||
var transport = NetworkManager.Singleton.GetComponent<Unity.Netcode.Transports.UTP.UnityTransport>();
|
||||
if (transport != null)
|
||||
{
|
||||
EditorGUILayout.LabelField($"Address: {transport.ConnectionData.Address}");
|
||||
EditorGUILayout.LabelField($"Port: {transport.ConnectionData.Port}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawQuickActions()
|
||||
{
|
||||
EditorGUILayout.LabelField("Quick Actions", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button("Open Connection Window"))
|
||||
{
|
||||
NetworkConnectionWindow.ShowWindow();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Test Connection"))
|
||||
{
|
||||
TestConnection();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private bool IsConnected()
|
||||
{
|
||||
return NetworkManager.Singleton != null &&
|
||||
(NetworkManager.Singleton.IsClient || NetworkManager.Singleton.IsServer);
|
||||
}
|
||||
|
||||
private string GetDetailedStatus()
|
||||
{
|
||||
if (NetworkManager.Singleton == null)
|
||||
return "NetworkManager Not Found";
|
||||
|
||||
if (NetworkManager.Singleton.IsHost)
|
||||
return "HOSTING";
|
||||
if (NetworkManager.Singleton.IsServer)
|
||||
return "SERVER RUNNING";
|
||||
if (NetworkManager.Singleton.IsClient)
|
||||
return "CONNECTED";
|
||||
|
||||
return "NOT CONNECTED";
|
||||
}
|
||||
|
||||
private Color GetStatusColor()
|
||||
{
|
||||
if (NetworkManager.Singleton == null)
|
||||
return new Color(0.8f, 0.3f, 0.3f);
|
||||
|
||||
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsClient || NetworkManager.Singleton.IsServer)
|
||||
return new Color(0.3f, 0.8f, 0.3f);
|
||||
|
||||
return new Color(0.8f, 0.6f, 0.3f);
|
||||
}
|
||||
|
||||
private void TestConnection()
|
||||
{
|
||||
Debug.Log($"[NetworkConnectionHelper] Connection test - Status: {_helper.GetStatus()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user