Пример #1
0
        void Start()
        {
            #region Listeners
            loginButton.onClick.AddListener(() => {
                GameSparksManager.Instance().AuthenticateUser(userNameInput.text, passwordInput.text, OnAuthentication);
            });

            registerButton.onClick.AddListener(() => {
                GameSparksManager.Instance().RegisterUser(userNameInput.text, passwordInput.text);
            });

            matchmakingButton.onClick.AddListener(() => {
                GameSparksManager.Instance().FindPlayers();
                matchDetails.text = "Searching For Players...";
            });

            MatchNotFoundMessage.Listener = (message) => {
                matchDetails.text = "No Match Found...";
            };

            MatchFoundMessage.Listener = (message) => {
                matchmakingButton.gameObject.SetActive(false);
                startGameButton.gameObject.SetActive(true);
            };

            MatchFoundMessage.Listener += OnMatchFound;

            startGameButton.onClick.AddListener(() => {
                GameSparksManager.Instance().StartNewRTSession(tempRTSessionInfo);
            });

            exitButton.onClick.AddListener(() => {
                //Destroys objects that need to be killed before closing
                GameObject[] gos = GameObject.FindGameObjectsWithTag("GameController");
                foreach (GameObject go in gos)
                {
                    Destroy(go);
                }
                Application.Quit();
            });

            logoutButton.onClick.AddListener(() => {
                SceneManager.LoadScene(0);
            });
            #endregion
        }
Пример #2
0
        //Coroutine for sending player movement
        private IEnumerator SendMovement()
        {
            //Checks if the player is actually moving before sending packet
            if ((this.transform.position != prevPos) || (this.transform.eulerAngles.y != prevRot) || (Mathf.Abs(Input.GetAxis("Vertical")) > 0) || (Mathf.Abs(Input.GetAxis("Horizontal")) > 0))
            {
                using (RTData data = RTData.Get()) {                                                                                               // we put a using statement here so that we can dispose of the RTData objects once the packet is sent
                    data.SetVector3(1, new Vector4(this.transform.position.x, this.transform.position.y, this.transform.position.z));              // add the position at key 1
                    data.SetVector3(2, new Vector3(velocity.x, velocity.y, 0));
                    data.SetFloat(3, this.transform.eulerAngles.y);                                                                                // add the rotation at key 2
                    GameSparksManager.Instance().GetRTSession().SendData(2, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data); // send the data
                }
                prevPos = this.transform.position;                                                                                                 // record position for any discrepancies
                prevRot = this.transform.eulerAngles.y;
            }

            yield return(new WaitForSeconds(updateRate));

            StartCoroutine(SendMovement());
        }
Пример #3
0
        public Text[] playerScoreHUDList, playerNamesHUDList; // these are the text-fields for each player's kills and name in the HUD panel. This is set from the editor

        void Start()
        {
            SpawnPoint[] allSpawners = FindObjectsOfType(typeof(SpawnPoint)) as SpawnPoint[];               //gets all the spawner scripts
            int          playerCount = GameSparksManager.Instance().GetSessionInfo().GetPlayerList().Count; //gets the number of players

            #region Setup Players
            playerList = new Player_Master[playerCount];//create a list to store the player scripts

            Debug.Log("GC| Found " + playerList.Length + " Players...");
            for (int i = 0; i < playerCount; i++)
            {
                Debug.Log("Player Counter " + i);
                for (int j = 0; j < allSpawners.Length; j++)
                {
                    Debug.Log("Spawn Counter" + j);
                    //if the spawner id and player id are the same, place the player here
                    if (allSpawners[j].playerPeerId == GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerID)
                    {
                        allSpawners[j].StartCountdown();//countdown to reset the spawner
                        int tempPeerID = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerID;
                        // if the current iteration is the player, set it up as the player.
                        if (GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerID == GameSparksManager.Instance().GetRTSession().PeerId)
                        {
                            //Creates the player
                            GameObject newPlayer = Instantiate(playerPrefab, allSpawners[j].gameObject.transform.position, allSpawners[j].gameObject.transform.rotation) as GameObject;

                            //Calls function to setup the player
                            newPlayer.GetComponent <Player_Master>().Setup(allSpawners[j].gameObject.transform, true, tempPeerID);

                            //Ensures Cameras are active
                            newPlayer.transform.GetChild(0).gameObject.SetActive(true);

                            //Set the players name
                            newPlayer.name = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerID.ToString();

                            //Set the players parent
                            newPlayer.transform.SetParent(this.transform);

                            // add the new tank object to the corresponding reference in the list
                            playerList[i] = newPlayer.GetComponent <Player_Master>();
                        }
                        else
                        {
                            //Creates the enemy player
                            GameObject enemyPlayer = Instantiate(enemyPrefabs[i], allSpawners[j].gameObject.transform.position, allSpawners[j].gameObject.transform.rotation) as GameObject;

                            //Calls function to setup the enemy player
                            enemyPlayer.GetComponent <Player_Master>().Setup(allSpawners[j].gameObject.transform, false, tempPeerID);

                            //Set the enemy's name
                            enemyPlayer.name = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerID.ToString();

                            //Set the enemy's parent
                            enemyPlayer.transform.SetParent(this.transform);

                            // add the new tank object to the corresponding reference in the list
                            playerList[i] = enemyPlayer.GetComponent <Player_Master>();
                        }
                        break;
                    }
                }
            }
            #endregion
        }
Пример #4
0
 //Sends a death notice to the player who died to tell them they died in on instance
 public void SendDeath()
 {
     using (RTData data = RTData.Get()) {
         GameSparksManager.Instance().GetRTSession().SendData(4, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data);// send the data
     }
 }
 void Awake()
 {
     instance = this;
     DontDestroyOnLoad(this.gameObject);//makes sure object isnt destroyed between scenes
 }