void Awake() { GameSparks.Api.Messages.MatchNotFoundMessage.Listener = (message) => { Debug.Log("No Match Found"); }; GameSparks.Api.Messages.MatchFoundMessage.Listener += OnMatchFound; GS.GameSparksAvailable += (isAvailable) => { if (isAvailable && GameSparksManager.PeerId() == -1) { if (useDeviceAuth) { GameSparksManager.Instance().DeviceAuthentication(OnAuthentication); } else { GameSparksManager.Instance().AuthenticateUser(userName, password, OnRegistration, OnAuthentication); } } }; }
private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage _message) { searchingPanel.SetActive(false); foundPanel.SetActive(true); 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 (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 } matchDetails.text = sBuilder.ToString(); // set the string to be the player-list field GameSparksManager.Instance().StartNewRTSession(new RTSessionInfo(_message)); }
/// <summary> /// Called when a player accepts the Match Found dialog box. Should send that they are ready for the match to start, once /// all players ready up, transition everyone to the TestLevel scene (make them load the scene async first, then when everyone /// is loaded, activate the scene on all clients. Once all scenes are activated, sync timers and begin countdown /// </summary> private void ReadyForMatch() { GameSparksManager.Instance().StartNewRTSession(tempRTSessionInfo); //Nux.SceneManager.Instance.LoadScene("TestLevel"); }
void UpdateUserStatus() { userStatus.text = (GS.Available ? "Connected" : "Disconnected") + ((GS.Authenticated && GameSparksManager.Instance().user != null) ? " | Logged in as " + GameSparksManager.Instance().user.displayName : " | Not authenticated"); }
public static void SendPacket(NetworkObject networkObject, RTData data, GameSparksRT.DeliveryIntent intent) { data.SetString((int)DataIndex.NetworkId, networkObject.networkId); GameSparksManager.Instance().SendRTData(OpCodes.NetworkObject, intent, data); }
/// <summary> /// Inicia a cena do jogo /// </summary> private void StartGame() { Debug.Log("StartGame"); GameSparksManager.Instance().FindPlayers(); }
void UpdateUserStatus() { userStatus.text = (GS.Available ? "Connected" : "Disconnected") + " | Logged in as " + GameSparksManager.Instance().user.displayName; }
void OnReadyButton() { GameSparksManager.Instance().SetPlayerReady(true); readyButton.interactable = false; }
private void SetupAllPlayers(PlayerSpawnPoint[] spawnPoints) { int playerCount = 1; if (GameSparksManager.Instance()) { playerCount = (int)GameSparksManager.Instance().GetSessionInfo().GetPlayerList().Count; } m_playerAvatarList = new Player[playerCount]; Debug.Log("GC| Found " + m_playerAvatarList.Length + " Players..."); // Loop through each player, and all spawn points, to assign each player to a spawn point based on the player's peerID for (int playerIndex = 0; playerIndex < playerCount; playerIndex++) { Debug.Log("GameController| playerIndex:" + playerIndex); for (int spawnerIndex = 0; spawnerIndex < spawnPoints.Length; spawnerIndex++) { Debug.Log(" GameController| Peer ID: " + GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID + " || SpawnID: " + spawnPoints[spawnerIndex].SpawnID); if (spawnPoints[spawnerIndex].SpawnID == GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID) { GameObject newAvatar = Instantiate(PlayerAvatarPrefab, spawnPoints[spawnerIndex].gameObject.transform.position, spawnPoints[spawnerIndex].gameObject.transform.rotation) as GameObject; newAvatar.name = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID.ToString(); m_playerAvatarList[playerIndex] = newAvatar.GetComponent <Player>(); // add the new tank object to the corresponding reference in the list if (GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID == GameSparksManager.Instance().GetRTSession().PeerId) { m_playerAvatarList[playerIndex].SetupPlayerAvatar(spawnPoints[spawnerIndex].gameObject.transform, true, Team.Blue); // @TODO - Setup HUD, setup player team to be read ThirdPersonCamera.SetMainTarget(newAvatar.transform); } else { m_playerAvatarList[playerIndex].SetupPlayerAvatar(spawnPoints[spawnerIndex].gameObject.transform, false, Team.Red); // @TODO - Setup HUD, setup player team to be read } break; } } } }
private void OnAuthentication(AuthenticationResponse _resp) { GameSparksManager.Instance().FindPlayers(matchShortCode); }
private void OnRegistration(RegistrationResponse _resp) { GameSparksManager.Instance().FindPlayers(matchShortCode); }