using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
namespace Multiplayer
|
|
{
|
|
|
|
public class ServerManager : MonoSingleton<ServerManager>
|
|
{
|
|
|
|
[SerializeField]
|
|
private bool StartOnAwake = true;
|
|
|
|
[SerializeField]
|
|
private int Port = 4444;
|
|
|
|
|
|
public Dictionary<int, Player> AllPlayers;
|
|
|
|
public NetworkServerSimple Server { get; private set; }
|
|
private LoginManager loginManager;
|
|
private PlayerServerManager playerManager;
|
|
|
|
|
|
|
|
private void Start()
|
|
{
|
|
if (StartOnAwake)
|
|
StartServer();
|
|
}
|
|
|
|
[ContextMenu("Start Server")]
|
|
public void StartServer()
|
|
{
|
|
StartServer(Port);
|
|
}
|
|
|
|
public void StartServer(int Port)
|
|
{
|
|
this.Port = Port;
|
|
AllPlayers = new Dictionary<int, Player>();
|
|
|
|
Server = new NetworkServerSimple();
|
|
Server.Configure(ChannelConfig.DefaultTopology());
|
|
|
|
Debug.Log("Starting Server on " + Port);
|
|
loginManager = new LoginManager(this);
|
|
playerManager = new PlayerServerManager(this);
|
|
|
|
Server.Listen(Port);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Server != null)
|
|
Server.Update();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|