You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
1.4 KiB

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 long Seed;
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);
Seed = System.DateTime.Now.Ticks;
Server.Listen(Port);
}
private void Update()
{
if (Server != null)
Server.Update();
}
}
}