void Start() { UpdateUserStatus(); GameSparks.Core.GS.GameSparksAvailable += (isAvailable) => { UpdateUserStatus(); }; // we add a custom listener to the on-click delegate of the login button so we don't need to create extra methods loginBttn.onClick.AddListener(() => { GameSparksManager.Instance().AuthenticateUser(userNameInput.text, passwordInput.text, OnRegistration, OnAuthentication); }); }
void Start() { GameSparks.Core.GS.GameSparksAvailable = (isAvailable) => { UpdateUserStatus(); }; findPanel.SetActive(true); searchingPanel.SetActive(false); foundPanel.SetActive(false); soloMatchmakingButton.onClick.AddListener(() => { FindMatch("solo"); }); duoMatchmakingButton.onClick.AddListener(() => { FindMatch("duo"); }); cancelButton.onClick.AddListener(() => { findPanel.SetActive(true); searchingPanel.SetActive(false); GameSparksManager.Instance().CancelMatchmaking(currentMatchCode); }); // this listener will update the text in the player-list field if no match was found GameSparks.Api.Messages.MatchNotFoundMessage.Listener = (message) => { searchingPanel.SetActive(false); foundPanel.SetActive(true); matchDetails.text = "No Match Found..."; }; GameSparks.Api.Messages.MatchFoundMessage.Listener = OnMatchFound; UpdateUserStatus(); }
void Start() { readyButton.onClick.AddListener(() => { OnReadyButton(); SetPlayerReady(GameSparksManager.PeerId()); }); // Player list var players = GameSparksManager.Instance().GetSessionInfo().GetPlayerList(); playerPanels = new List <Transform>(); foreach (var player in players) { Transform playerPanel = Instantiate(PlayerPanelPrefab, playerList, false).transform; playerPanel.Find("DisplayName").GetComponent <TMP_Text>().text = player.displayName; playerPanel.Find("ReadyIcon").GetComponent <Image>().enabled = false; playerPanels.Add(playerPanel); } }
public void StartMatch() { matchStartCountdown.gameObject.SetActive(false); inGameUi.SetActive(true); topCamera.SetActive(false); if (!IsHost) { return; } spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint"); for (int i = 0; i < playerList.Length; i++) { int peerId = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerId; Vector3 spawnPos = spawnPoints[i].transform.position; Quaternion spawnRot = spawnPoints[i].transform.rotation; playerList[i] = NetworkManager.NetworkInstantiate(playerPrefab, peerId, spawnPos, spawnRot).GetComponent <Player>(); } }
public static GameObject NetworkInstantiate(GameObject original, int owner = 1, Vector3 position = new Vector3(), Quaternion rotation = new Quaternion()) { // Copy GameObject copy = UnityEngine.Object.Instantiate(original); string objectId = NetworkObject.GenerateId(); copy.name += " (" + objectId + ")"; copy.transform.position = position; copy.transform.rotation = rotation; // Get all the NetworkObjects NetworkObject[] nos = copy.GetComponentsInChildren <NetworkObject>(); // Set all the network ids for (uint i = 0; i < nos.Length; i++) { nos[i].SetOwner(owner); nos[i].SetId(objectId + "-" + i); } using (RTData data = RTData.Get()) { // Set the prefab index data.SetInt(1, NetworkPrefabs.instance.prefabs.IndexOf(original)); data.SetInt(2, owner); data.SetString(3, objectId); data.SetVector3(4, position); data.SetVector3(5, rotation.eulerAngles); // Send GameSparksManager.Instance().SendRTData(OpCodes.NetworkInstantiate, GameSparksRT.DeliveryIntent.RELIABLE, data); } return(copy); }
void Awake() { GameSparks.Api.Messages.MatchNotFoundMessage.Listener = (message) => { Debug.Log("No Match Found"); }; GameSparks.Api.Messages.MatchFoundMessage.Listener += OnMatchFound; GameSparks.Core.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)); }
void UpdateUserStatus() { userStatus.text = (GameSparks.Core.GS.Available ? "Connected" : "Disconnected") + ((GameSparks.Core.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); }
void Awake() { instance = this; // if not, give it a reference to this class... DontDestroyOnLoad(this.gameObject); // and make this object persistent as we load new scenes }
private void OnAuthentication(AuthenticationResponse _resp) { GameSparksManager.Instance().FindPlayers(matchShortCode); }
private void OnRegistration(RegistrationResponse _resp) { GameSparksManager.Instance().FindPlayers(matchShortCode); }
void OnReadyButton() { GameSparksManager.Instance().SetPlayerReady(true); readyButton.interactable = false; }
void UpdateUserStatus() { userStatus.text = (GameSparks.Core.GS.Available ? "Connected" : "Disconnected") + " | Logged in as " + GameSparksManager.Instance().user.displayName; }