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.
 
 
 

77 lines
1.6 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 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);
}
[ContextMenu("Start Game")]
public void StartGame()
{
foreach (Player player in AllPlayers.Values)
{
player.Connection.Send(PlayerMsgID.GameStart, new PlayerMsg(player.ID));
}
}
private void Update()
{
if (Server != null)
Server.Update();
}
}
}