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.

68 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace Multiplayer
  6. {
  7. public class ServerManager : MonoSingleton<ServerManager>
  8. {
  9. [SerializeField]
  10. private bool StartOnAwake = true;
  11. [SerializeField]
  12. private int Port = 4444;
  13. public Dictionary<int, Player> AllPlayers;
  14. public NetworkServerSimple Server { get; private set; }
  15. private LoginManager loginManager;
  16. private PlayerServerManager playerManager;
  17. private void Start()
  18. {
  19. if (StartOnAwake)
  20. StartServer();
  21. }
  22. [ContextMenu("Start Server")]
  23. public void StartServer()
  24. {
  25. StartServer(Port);
  26. }
  27. public void StartServer(int Port)
  28. {
  29. this.Port = Port;
  30. AllPlayers = new Dictionary<int, Player>();
  31. Server = new NetworkServerSimple();
  32. Server.Configure(ChannelConfig.DefaultTopology());
  33. Debug.Log("Starting Server on " + Port);
  34. loginManager = new LoginManager(this);
  35. playerManager = new PlayerServerManager(this);
  36. Server.Listen(Port);
  37. }
  38. private void Update()
  39. {
  40. if (Server != null)
  41. Server.Update();
  42. }
  43. }
  44. }