IEnumerator CoroutineConnect(string serverIp, int myPort, int serverPort, System.Action callback = null) { Debug.Log("Connection try started"); Network.InitAsClient(serverIp, myPort, serverPort); while (Network.Client.ConnectionId < 0) { yield return(null); } yield return(null); if (callback != null) { callback(); } if (OnConnect != null) { OnConnect(this, Network.Client.ConnectionId); } Network.AddListener(new RespawnListener()); Debug.Log("Connected"); yield return(new WaitForSeconds(1.0f)); { var e = new SpawnRequestEvent(Network.Client.ConnectionId); Network.Client.Send(e); } }
public bool Execute(EventBase e) { SpawnRequestEvent respawn = (SpawnRequestEvent)e; Debug.Log("Respawned?"); if (respawn.m_sessionId == Network.Client.ConnectionId) { Debug.Log("RESPAWNED INDEED"); } return(true); }
public bool Execute(EventBase e) { SpawnRequestEvent input = (SpawnRequestEvent)e; PlayerPawn pawn = m_world.TryGetPawn(input.m_sessionId); //Console.WriteLine("Looking for pawn with id " + input.m_sessionId + ": " + pawn); if (pawn != null && !pawn.m_isPlayingNow) { pawn.m_isPlayingNow = true; m_world.RespawnPlayer(input.m_sessionId); } return(true); }
public void RespawnPlayer(int sessionId) { PlayerPawn pawn = null; m_players.TryGetValue(sessionId, out pawn); if (pawn != null) { Vector2 position = GetRandomPoint(5); pawn.Respawn(position); var spawnEvent = new SpawnRequestEvent(sessionId, true); spawnEvent.m_startPosition = position; Network.Log("Pawn " + sessionId + " respawned at " + position); Network.Server.Send(spawnEvent, sessionId); } }
public EventType GetEventType() { return((EventType)SpawnRequestEvent.GetStaticId()); }