Untitled
unknown
plain_text
3 years ago
1.5 kB
12
Indexable
using Riptide;
using Riptide.Utils;
using UnityEngine;
public enum ServerToClientId : ushort
{
playerSpawned = 1,
}
public enum ClientToServerId : ushort
{
name = 1,
}
public class NetworkManager : MonoBehaviour
{
private static NetworkManager _singleton;
public static NetworkManager Singleton
{
get => _singleton;
private set
{
if (_singleton == null)
_singleton = value;
else if (_singleton != value)
{
Debug.Log($"{nameof(NetworkManager)} instance already exists, destroying duplicate!");
Destroy(value);
}
}
}
public Server Server { get; private set; }
[SerializeField] private ushort port;
[SerializeField] private ushort maxClientCount;
private void Awake()
{
Singleton = this;
}
private void Start()
{
Application.targetFrameRate = 60;
RiptideLogger.Initialize(Debug.Log, Debug.Log, Debug.LogWarning, Debug.LogError, false);
Server = new Server();
Server.Start(port, maxClientCount);
// Server.ClientDisconnected += PlayerLeft;
}
private void FixedUpdate()
{
Server.Update();
}
private void OnApplicationQuit()
{
Server.Stop();
}
/* private void PlayerLeft(object sender, ClientDisconnectedEventArgs e)
{
Destroy(Player.list[e.Id].gameObject);
}*/
}
Editor is loading...