private void Update() { if (Input.GetMouseButtonDown(0)) { isDragging = true; } if (Input.GetMouseButtonUp(0)) { isDragging = false; } if (isDragging && playerInitialized) { // The game server is server authoritative. That is, it is the // "source of truth", so only update the UI based on the information // it sends from the GameStateUpdatePacket in response to PlayerUpdateStatePackets // it gets from each player. syncServer.SendPlayerPosition(ScreenToWorldPosition(new Vector2(Input.mousePosition.x, Input.mousePosition.y))); } // Process all packets that have been received by the server thus far byte[] data; while (syncServer.GetNextPacket(out data)) { var packet = PacketFactory.BytesToPacket(data); var byteBuffer = new ByteBuffer(data); switch ((Opcode)packet.Opcode) { case Opcode.Success: Debug.Log("Success packet received"); break; case Opcode.GameStateUpdate: OnGameStateUpdated(GameStateUpdatePacket.GetRootAsGameStateUpdatePacket(byteBuffer)); break; case Opcode.MatchSuccess: // All players have entered the match, the game can now be played. // set the tickRate so that we can properly interpolate animations on the client side tickRate = MatchSuccessPacket.GetRootAsMatchSuccessPacket(byteBuffer).TickRate; Debug.Log("Match found, joining... Tick Rate: " + tickRate); OnMatchReady(); break; case Opcode.GameOver: OnGameOver(GameOverPacket.GetRootAsGameOverPacket(byteBuffer)); break; default: Debug.Log($"Packet received with Opcode={(Opcode)packet.Opcode}"); break; } } // If we've initialized our players, lets start interpolating between circlesPreviousPositions and circlesDesiredPositions if (playerInitialized) { DrawAllCircles(); } }
public MatchReadyArgs(MatchSuccessPacket matchSuccessPacket) { this.matchSuccessPacket = matchSuccessPacket; }