Exemplo n.º 1
0
 private void OnMatchFound(MatchFoundMessage obj)
 {
     Debug.Log("OnMatchFound");
     _rtSessionInfo = new RTSessionInfo(obj);
     GameSparksManager.Instance().StartNewRtSession(_rtSessionInfo);
     //SceneManager.LoadScene("GamePlay");
 }
Exemplo n.º 2
0
    private void Start()
    {
        cinemachineCamera = GameObject.FindObjectOfType <CinemachineVirtualCamera>();

        if (MyGameSparksManager.Instance() != null)
        {
            RTSessionInfo sessionInfo = MyGameSparksManager.Instance().GetRTSessionInfo();
            if (sessionInfo != null)
            {
                var playerList = sessionInfo.GetPlayerList();
                survivors = new List <Survivor>(playerList.Count);

                Debug.Log("PLAYER LIST COUNT: " + playerList.Count);

                for (var index = 0; index < playerList.Count; index++)
                {
                    RTSessionInfo.RtPlayer rtPlayer = playerList[index];

                    Debug.Log(rtPlayer);

                    Color playerColor = PLAYER_COLORS[index];

                    CreateAndSetupPlayer(rtPlayer.PeerId,
                                         rtPlayer.DisplayName,
                                         rtPlayer.isMe,
                                         playerColor);
                }
            }
        }
        else
        {
            CreateAndSetupPlayer(0, "LocalPlayer", true, Color.gray);
        }
    }
Exemplo n.º 3
0
    void MatchFound(MatchFoundMessage message)
    {
        session_info = new RTSessionInfo(message);
        ManagersController.Message(Message.Create(this, MessageData.EVENT_SET_ONLINE_PLAYERS, session_info.players));

        #region Create Session

        session = this.gameObject.GetComponent <GameSparksRTUnity> ();

        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", session_info.PortID)
                                       .AddString("host", session_info.HostURL)
                                       .AddString("accessToken", session_info.AccessToken);
        FindMatchResponse response = new FindMatchResponse(mockedResponse);

        session.Configure(
            response,
            peerID => OnPlayerConnected(peerID),
            peerID => OnPlayerDisconnected(peerID),
            ready => OnRTReady(ready),
            packet => OnPacketRecieved(packet)
            );

        session.Connect();

        #endregion
    }
Exemplo n.º 4
0
    public void StartNewRTSession(RTSessionInfo _info)
    {
        Debug.Log("GSM| Creating New RT Session Instance...");
        sessionInfo       = _info;
        gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); // Adds the RT script to the game
        // In order to create a new RT game we need a 'FindMatchResponse' //
        // This would usually come from the server directly after a successful MatchmakingRequest //
        // However, in our case, we want the game to be created only when the first player decides using a button //
        // therefore, the details from the response is passed in from the gameInfo and a mock-up of a FindMatchResponse //
        // is passed in. //
        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)_info.GetPortID())
                                       .AddString("host", _info.GetHostURL())
                                       .AddString("accessToken", _info.GetAccessToken()); // construct a dataset from the game-details

        FindMatchResponse response = new FindMatchResponse(mockedResponse);               // create a match-response from that data and pass it into the game-config

        // So in the game-config method we pass in the response which gives the instance its connection settings //
        // In this example, I use a lambda expression to pass in actions for
        // OnPlayerConnect, OnPlayerDisconnect, OnReady and OnPacket actions //
        // These methods are self-explanatory, but the important one is the OnPacket Method //
        // this gets called when a packet is received //

        gameSparksRTUnity.Configure(response,
                                    (peerId) => { OnPlayerConnectedToGame(peerId); },
                                    (peerId) => { OnPlayerDisconnected(peerId); },
                                    (ready) => { OnRTReady(ready); },
                                    (packet) => { OnPacketReceived(packet); });
        gameSparksRTUnity.Connect(); // when the config is set, connect the game
    }
Exemplo n.º 5
0
    private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage _message)
    {
        tempRTSessionInfo = new RTSessionInfo(_message);
        GameSparksManager.Instance().StartNewRTSession(tempRTSessionInfo);

        Debug.Log("Match Found");
    }
Exemplo n.º 6
0
    private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage _message)
    {
        Debug.Log("GM| Match Found!...");

        // Store the MatchFoundMessage data and have MultiplayerNetworkingManager start a RT session
        // Since MatchFoundMessage only happens once after sending a MatchmakingRequest (to start a new game), a new RT session instance is created each time.
        tempRTSessionInfo = new RTSessionInfo(_message);
        MultiplayerNetworkingManager.Instance().StartNewRTSession(tempRTSessionInfo);
    }
Exemplo n.º 7
0
    public void GenerateRTSessionJSON()
    {
        List <RTSessionInfo.RTPlayer> players = new List <RTSessionInfo.RTPlayer>();

        players.Add(new RTSessionInfo.RTPlayer("DisplayName1", "id1", 100));
        players.Add(new RTSessionInfo.RTPlayer("DisplayName2", "id2", 200));
        RTSessionInfo rTSessionInfo = new RTSessionInfo("HostURLR", "AcessTokenR", 1000, "MatchIDR", players);

        Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(rTSessionInfo, Newtonsoft.Json.Formatting.Indented));
    }
Exemplo n.º 8
0
    private void StartNewSession(RTSessionInfo sessionInfo, MatchFoundMessage resp)
    {
        Debug.Log("GSM| Creating New RT Session Instance...");

        RtGS = gameObject.AddComponent <GameSparksRTUnity>();

        RtGS.Configure(resp,
                       (peerId) => { OnPlayerConnectedToGame(peerId); },
                       (peerId) => { OnPlayerDisconnected(peerId); },
                       (ready) => { OnRTReady(ready); },
                       (packet) => { OnPacketReceived(packet); }
                       );
        RtGS.Connect();
    }
Exemplo n.º 9
0
    public void Start()
    {
        GameSparks.Api.Messages.MatchFoundMessage.Listener += OnMatch;

        GameSparks.Api.Messages.ScriptMessage.Listener += (message) =>
        {
            m_pText.text += message.Data.BaseData["INFO"] + "\n\n";
            RTSessionInfo tSession = GameSparksManager.Instance.PSessionInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <RTSessionInfo>(message.Data.BaseData["INFO"] as string);
            //GameSparksManager.Instance.StartNewRTSession(tSession);
            GameSparksManager.Instance.gameSparksRTUnity.Configure(tSession.HostURL, tSession.PortID, tSession.GetAccessToken, null, null, null, OnPacketReceived);
            GameSparksManager.Instance.gameSparksRTUnity.Connect();
        };

        GameSparks.Api.Messages.MatchNotFoundMessage.Listener = (message) =>
        {
            Debug.Log("Error to find match");
        };

        //  gameSparksRTUnity.Configure(response, )
    }
Exemplo n.º 10
0
    public void StartNewRTSession(RTSessionInfo _info)
    {
        Debug.Log("GSM| Creating New RT Session Instance...");
        sessionInfo       = _info;
        gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>();

        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)_info.GetPortID())
                                       .AddString("host", _info.GetHostURL())
                                       .AddString("accessToken", _info.GetAccessToken());

        FindMatchResponse response = new FindMatchResponse(mockedResponse);

        gameSparksRTUnity.Configure(response,
                                    (peerId) => { OnPlayerConnectedToGame(peerId); },
                                    (peerId) => { OnPlayerDisconnected(peerId); },
                                    (ready) => { OnRTReady(ready); },
                                    (packet) => { OnPacketReceived(packet); });
        gameSparksRTUnity.Connect();
    }
Exemplo n.º 11
0
    private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage _message)
    {
        Debug.Log("GameSparks| Match Found!...");

        System.Text.StringBuilder sBuilder = new System.Text.StringBuilder();
        sBuilder.AppendLine("Opponents:" + _message.Participants.Count());
        sBuilder.AppendLine("_________________");
        sBuilder.AppendLine(); // we'll leave a space between the player-list and the match data
        foreach (GameSparks.Api.Messages.MatchFoundMessage._Participant player in _message.Participants)
        {
            sBuilder.AppendLine("Player:" + player.PeerId + " User Name:" + player.DisplayName); // add the player number and the display name to the list
        }

        tempRTSessionInfo = new RTSessionInfo(_message);

        Backend.Utility.MakeNewGenericPopup("Match Found!", sBuilder.ToString(), false);

        // TEMP @TODO: Read ReadyForMatch summary
        Invoke("ReadyForMatch", 2f);
    }
Exemplo n.º 12
0
    public void StartNewRealTimeSession(RTSessionInfo sessionInfo)
    {
        m_rtSessionInfo   = sessionInfo;
        gameSparksRTUnity = gameObject.AddComponent <GameSparksRTUnity>();

        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)sessionInfo.GetPortId())
                                       .AddString("host", sessionInfo.GetHostUrl())
                                       .AddString("accessToken", sessionInfo.GetAccessToken());

        FindMatchResponse response = new FindMatchResponse(mockedResponse);


        gameSparksRTUnity.Configure(response,
                                    OnPlayerConnect,
                                    OnPlayerDisconnect,
                                    OnReady,
                                    OnPacket);

        gameSparksRTUnity.Connect();
    }
Exemplo n.º 13
0
    private void OnMatchFound(MatchFoundMessage message)
    {
        Debug.Log("Match Found!...");
        StringBuilder sBuilder = new StringBuilder();

        sBuilder.AppendLine("Match Found...");
        sBuilder.AppendLine("Host URL:" + message.Host);
        sBuilder.AppendLine("Port:" + message.Port);
        sBuilder.AppendLine("Access Token:" + message.AccessToken);
        sBuilder.AppendLine("MatchId:" + message.MatchId);
        sBuilder.AppendLine("Opponents:" + message.Participants.Count());
        sBuilder.AppendLine("_________________");
        sBuilder.AppendLine();          // we'll leave a space between the player-list and the match data
        foreach (MatchFoundMessage._Participant player in message.Participants)
        {
            sBuilder.AppendLine("Player:" + player.PeerId + " User Name:" + player.DisplayName); // add the player number and the display name to the list
        }
        m_playerList.text = sBuilder.ToString();                                                 // set the string to be the player-list field

        m_rtSessionInfo = new RTSessionInfo(message, GS.GSPlatform.UserId);
        ToggleStartMatch(true);
    }
Exemplo n.º 14
0
    private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage _message)
    {
        Debug.Log("Match Found!...");
        StringBuilder sBuilder = new StringBuilder();

        sBuilder.AppendLine("Match Found...");
        sBuilder.AppendLine("Host URL:" + _message.Host);
        sBuilder.AppendLine("Port:" + _message.Port);
        sBuilder.AppendLine("Access Token:" + _message.AccessToken);
        sBuilder.AppendLine("MatchId:" + _message.MatchId);
        sBuilder.AppendLine("Opponents:" + _message.Participants.Count());
        sBuilder.AppendLine("_________________");
        sBuilder.AppendLine();
        foreach (GameSparks.Api.Messages.MatchFoundMessage._Participant player in _message.Participants)
        {
            sBuilder.AppendLine("Player:" + player.PeerId + " User Name:" + player.DisplayName);
        }
        playerList.text = sBuilder.ToString();

        tempRTSessionInfo = new RTSessionInfo(_message);
        matchmakingBttn.gameObject.SetActive(false);
        startGameBttn.gameObject.SetActive(true);
    }
Exemplo n.º 15
0
    /// <summary>
    /// This is called when a match is found
    /// </summary>
    /// <param name="response">Resp.</param>
    private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage response)
    {
        tempRTSessionInfo = new RTSessionInfo(response); // we'll store the match data until we need to create an RT session instance
        matchMakingButton.gameObject.SetActive(false);
        startGameButton.gameObject.SetActive(true);

        Debug.Log("Match Found!...");
        StringBuilder sBuilder = new StringBuilder();

        sBuilder.AppendLine("Match Found...");
        sBuilder.AppendLine("Host URL:" + response.Host);
        sBuilder.AppendLine("Port:" + response.Port);
        sBuilder.AppendLine("Access Token:" + response.AccessToken);
        sBuilder.AppendLine("MatchId:" + response.MatchId);
        sBuilder.AppendLine("Opponents:" + response.Participants.Count());
        sBuilder.AppendLine("_________________");
        sBuilder.AppendLine();
        foreach (GameSparks.Api.Messages.MatchFoundMessage._Participant player in response.Participants)
        {
            sBuilder.AppendLine("Player:" + player.PeerId + " User Name:" + player.DisplayName); // add the player number and the display name to the list
        }
        Debug.Log(sBuilder.ToString());
    }
Exemplo n.º 16
0
    private void OnMatchFound(MatchFoundMessage resp)
    {
        Debug.Log(resp.JSONString);

        bool assigned = false;

        foreach (var participant in resp.Participants)
        {
            if (participant.Id == UserId)
            {
                PeerId = (int)participant.PeerId;

                if (!assigned)
                {
                    IsHost = true;

                    assigned = true;
                }
            }
        }

        sessionInfo = new RTSessionInfo(resp);
        StartNewSession(sessionInfo, resp);
    }
Exemplo n.º 17
0
    void InstantiatePlayers(RTSessionInfo session)
    {
        Transform         thisTransform     = transform;
        List <RTPlayer>   players           = session.PlayerList;
        GameSparksRTUnity gameSparksSession = m_gameSparksManager.RTSession;
        EnemyGenerator    enemyGenerator    = GameObject.Find("EnemyGenerator").GetComponent <EnemyGenerator>();
        int count = players.Count;

        enemyGenerator.players = new Rigidbody2D[count];

        m_players      = new PlayerController[count];
        m_turrets      = new Turret[count];
        m_playerHealth = new PlayerHealth[count];

        if (PlayerPrefabs.Length < count)
        {
            Debug.LogError("Player prefabs less than connected players!");
            return;
        }
        if (m_spawnPoints.Length < count)
        {
            Debug.LogError("Spawn points less than connected players!");
            return;
        }
        players.Sort((p, p2) => (p.PeerId.CompareTo(p2.PeerId)));

        for (int i = 0; i < count; ++i)
        {
            // Spawn Player
            GameObject player = Instantiate(
                PlayerPrefabs[i],
                m_spawnPoints[i].position,
                m_spawnPoints[i].rotation
                );
            Transform        playerTransform  = player.transform;
            PlayerController playerController = player.GetComponent <PlayerController>();
            m_playerHealth[i]         = player.GetComponent <PlayerHealth>();
            m_turrets[i]              = player.GetComponent <Turret>();
            enemyGenerator.players[i] = player.GetComponent <Rigidbody2D>();
            player.name                 = "Player " + players[i].PeerId.ToString();
            playerController.PeerID     = players[i].PeerId;
            playerController.UpdateRate = _playerUpdateRate;
            playerTransform.SetParent(thisTransform);
            m_turrets[i].BulletContainer   = m_bulletContainer;
            m_turrets[i].ParticleContainer = m_particleContainer;


            bool isPlayer = players[i].PeerId == gameSparksSession.PeerId;
            if (isPlayer)
            {
                m_camera.ObjectToFollow = playerTransform;
            }

            playerController.GameSparks = m_gameSparksManager;
            playerController.SetupMultiplayer(m_spawnPoints[i], isPlayer);

            // Set player multiplayer component instead...
            m_players[i] = playerController;

            // Spawn HpBar
            GameObject hpBar = Instantiate(m_hpBarPrefab);
            hpBar.transform.SetParent(UiCanvas);
            hpBar.GetComponent <FollowTarget>().target = playerTransform;
            HpBarUi hpBarUi = hpBar.GetComponent <HpBarUi>();
            hpBarUi.Health = m_playerHealth[i];
            m_playerHealth[i]._onPlayerHpModified.AddListener(hpBarUi.UpdateHealth);
            m_playerHealth[i]._onPlayerDeath.AddListener(PlayerDead);
        }

        // Don't generate if not host
        m_enemyGenerator.GameSparksManager = m_gameSparksManager;
        IsHost = m_gameSparksManager.RTSession.PeerId == 1;
        m_enemyGenerator.SetupMultiplayer(IsHost);
        m_playerScore.MultiplayerManager = this;
    }