using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; namespace Multiplayer { public class PlayerServerManager { private ServerManager ServerManager; public PlayerServerManager(ServerManager ServerManager) { this.ServerManager = ServerManager; RegisterHandlers(); } private void RegisterHandlers() { ServerManager.Server.RegisterHandler(PlayerMsgID.Position, RecievePosition); } private void RecievePosition(NetworkMessage msg) { VectorMsg vectorMsg; if (!Utility.ReadMessage(msg, out vectorMsg)) return; if (!ServerManager.AllPlayers.ContainsKey(vectorMsg.ID)) { Debug.Log("Recieved position from unknown player"); return; } Player player = ServerManager.AllPlayers[vectorMsg.ID]; player.Position = vectorMsg.vector; foreach(Player otherPlayer in ServerManager.AllPlayers.Values) { if (otherPlayer.Equals(player)) continue; otherPlayer.Connection.Send(PlayerMsgID.Position, vectorMsg); } } } }