// // Tries to grab necessary components if they haven't been already. // // Returns true if all components were verified to be grabbed. // private bool TryToGrabComponents() // { // if (this.matchDataBroadcaster == null) // this.matchDataBroadcaster = FindObjectOfType<MatchDataBroadcaster>(); // if (this.matchController == null) // this.matchController = FindObjectOfType<MatchController>(); // if (this.matchDataBroadcaster == null) // return false; // if (this.matchController == null) // return false; // return true; // } private IEnumerator GrabComponentsCoroutine() { while (this.matchDataBroadcaster == null) { this.matchDataBroadcaster = FindObjectOfType <MatchDataBroadcaster>(); yield return(null); } while (this.matchController == null) { this.matchController = FindObjectOfType <MatchController>(); yield return(null); } while (this.gridController == null) { this.gridController = FindObjectOfType <GridController>(); yield return(null); } while (this.hudController == null) { this.hudController = FindObjectOfType <HudController>(); yield return(null); } }
private void UpdateMoneyHud() { this.lastKnownPlayerMoneyStr = matchDataBroadcaster.PlayerMoneyStr; if (this.lastKnownUsernameStr != matchDataBroadcaster.UsernameListStr) { // TODO: Sanitize this!!! this.lastKnownUsernameStr = matchDataBroadcaster.UsernameListStr; this.usernames = MatchDataBroadcaster.UnpackStringData(this.lastKnownUsernameStr); } if (this.lastKnownPlayerMoneyStr != "") { this.playerMoneyAmounts = MatchController.UnpackPlayerMoneyStr(this.lastKnownPlayerMoneyStr); Debug.Log(debugTag + "Player Money String: " + this.lastKnownPlayerMoneyStr); for (int i = 0; i < usernames.Count; i++) { string username; if (usernames[i] != null) { username = usernames[i]; } else { username = "******" + (i + 1); } this.playerMoneyText[i].text = "<b>" + username + "</b>'s Cash: <b>$" + playerMoneyAmounts[i] + "</b>"; } } }
public void DisplayWinner(int winnerId) { string username = MatchDataBroadcaster.UnpackStringData(matchDataBroadcaster.UsernameListStr)[winnerId - 1]; Debug.Log(debugTag + "PLAYER " + winnerId + " WINS!"); winnerText.text = ("<b>" + username + "</b> WINS!"); winnerText.color = ColorPalette.GetDefaultPlayerColor(winnerId, 500, false); winnerObject.SetActive(true); }
public void UpdateUsernames() { for (int i = 0; i < usernameCache.Count; i++) { Players[i].Username = usernameCache[i]; Debug.Log(debugTag + "I updated Player " + Players[i].Id + " to the name " + usernameCache[i]); } matchDataBroadcaster.UsernameListStr = MatchDataBroadcaster.PackData(usernameCache); }
void Awake() { if (this.matchController == null) { this.matchController = FindObjectOfType <MatchController>(); } if (this.matchDataBroadcaster == null) { this.matchDataBroadcaster = FindObjectOfType <MatchDataBroadcaster>(); } }
// [Server] Grabs the MatchDataBroadcaster from this parent GameObject // On the client, they will grab the same MatchDataBroadcaster themselves in a different script. private void GrabMatchDataBroadCaster() { matchDataBroadcaster = this.gameObject.GetComponent <MatchDataBroadcaster>(); if (matchDataBroadcaster != null) { Debug.Log(debugTag + "MatchDataBroadcaster was found!"); } else { Debug.LogError(debugTag.error + "MatchDataBroadcaster was NOT found!"); } }
// [Client] Grabs the MatchDataBroadcaster from the MatchManager GameObject. private IEnumerator GrabMatchDataBroadCasterCoroutine() { if (matchDataBroadcaster == null) { matchDataBroadcaster = this.gameObject.GetComponent <MatchDataBroadcaster>(); if (matchDataBroadcaster != null) { Debug.Log(debugTag + "MatchDataBroadcaster was found!"); } } while (this.gameObject == null || matchDataBroadcaster == null) { Debug.LogError(debugTag.error + "MatchDataBroadcaster was NOT found!"); yield return(null); } }
void Awake() { // Look for the MatchManager first --------------------------------------------------------- referenceObj = GameObject.Find("MatchManager(Clone)"); // If found, swipe the config info to know how many Player objects to destroy -------------- if (referenceObj != null) { MatchDataBroadcaster mdb = referenceObj.GetComponent <MatchDataBroadcaster>(); MatchConfig config = JsonUtility.FromJson <MatchConfig>(mdb.MatchConfigStr); for (int i = 1; i <= config.MaxPlayerCount; i++) { string playerStr; playerStr = "Player (" + i + ")"; referenceObj = GameObject.Find(playerStr); SafeDestroy(referenceObj); } } // Attempt to stop hosting and destroy the NetworkManager ---------------------------------- referenceObj = GameObject.Find("NetworkManager"); if (referenceObj != null) { NetworkManager networkManager = referenceObj.GetComponent <NetworkManager>(); if (networkManager != null) { networkManager.StopHost(); // networkManager.StopClient(); } SafeDestroy(referenceObj); } // Continue by destroying the MatchManager, as it's not needed anymore --------------------- referenceObj = GameObject.Find("MatchManager(Clone)"); SafeDestroy(referenceObj); }
private IEnumerator Initialize() { // Grab the MatchDataBroadcaster while (matchDataBroadcaster == null) { matchDataBroadcaster = FindObjectOfType <MatchDataBroadcaster>(); yield return(null); } // Grab the Match Text yield return(StartCoroutine(InitMatchText())); // Get the match config while (matchDataBroadcaster.MatchConfigStr == null) { yield return(null); } config = JsonUtility.FromJson <MatchConfig>(matchDataBroadcaster.MatchConfigStr); // Get the current match data while (matchDataBroadcaster.MatchDataStr == null) { yield return(null); } this.matchData = JsonUtility.FromJson <MatchData>(matchDataBroadcaster.MatchDataStr); this.matchDataStr = matchDataBroadcaster.MatchDataStr; // Grab the Money Text yield return(StartCoroutine(InitMoneyText())); // Set the initialized flag to true initialized = true; // Finally, send the first UI update UpdateHud(); }