캐릭터 움직임 및 애니메이션
This commit is contained in:
100
Assets/Scripts/UI/ConnectionUI.cs
Normal file
100
Assets/Scripts/UI/ConnectionUI.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
using Unity.Netcode.Transports.UTP;
|
||||
|
||||
namespace Colosseum.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 네트워크 연결 설정 (Inspector에서 제어)
|
||||
/// </summary>
|
||||
public class ConnectionUI : MonoBehaviour
|
||||
{
|
||||
[Header("Connection Settings")]
|
||||
[SerializeField] private string ipAddress = "127.0.0.1";
|
||||
[SerializeField] private ushort port = 7777;
|
||||
|
||||
[Header("Status (Read Only)")]
|
||||
[SerializeField, Tooltip("현재 연결 상태")] private string connectionStatus = "Disconnected";
|
||||
|
||||
private UnityTransport transport;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
transport = NetworkManager.Singleton?.GetComponent<UnityTransport>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UpdateTransportSettings();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateConnectionStatus();
|
||||
}
|
||||
|
||||
private void UpdateConnectionStatus()
|
||||
{
|
||||
if (NetworkManager.Singleton == null)
|
||||
{
|
||||
connectionStatus = "No NetworkManager";
|
||||
return;
|
||||
}
|
||||
|
||||
if (NetworkManager.Singleton.IsServer && NetworkManager.Singleton.IsHost)
|
||||
connectionStatus = "Host";
|
||||
else if (NetworkManager.Singleton.IsServer)
|
||||
connectionStatus = "Server";
|
||||
else if (NetworkManager.Singleton.IsClient)
|
||||
connectionStatus = NetworkManager.Singleton.IsConnectedClient ? "Connected" : "Connecting...";
|
||||
else
|
||||
connectionStatus = "Disconnected";
|
||||
}
|
||||
|
||||
public void StartHost()
|
||||
{
|
||||
UpdateTransportSettings();
|
||||
NetworkManager.Singleton.StartHost();
|
||||
Debug.Log("[Network] Started as Host");
|
||||
}
|
||||
|
||||
public void StartClient()
|
||||
{
|
||||
UpdateTransportSettings();
|
||||
NetworkManager.Singleton.StartClient();
|
||||
Debug.Log($"[Network] Connecting to {ipAddress}:{port}...");
|
||||
}
|
||||
|
||||
public void StartServer()
|
||||
{
|
||||
UpdateTransportSettings();
|
||||
NetworkManager.Singleton.StartServer();
|
||||
Debug.Log("[Network] Started as Server");
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
if (NetworkManager.Singleton != null)
|
||||
{
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
Debug.Log("[Network] Disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTransportSettings()
|
||||
{
|
||||
if (transport != null)
|
||||
{
|
||||
transport.SetConnectionData(ipAddress, port);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (Application.isPlaying && transport != null)
|
||||
{
|
||||
UpdateTransportSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user