void subscribeToGame(MinigameBase game) { game.onScoreIncrease += onScoreIncrease; game.onScoreDecrease += onScoreDecrease; game.onComboEventPassed += onComboEventPassed; game.onComboEventFailed += onComboEventFailed; }
void onScoreDecrease(MinigameBase sender, int delta) { #if SEND_EVENTS_ON_SCORE_CHANGE int gameIdx = games.IndexOf(sender); int nextGameIdx = (gameIdx + 1) % games.Count; games[nextGameIdx].onBadEvent(delta); #endif metagame.onBadEvent(delta); }
IEnumerator findGameObjectsAfterDelay() { games = new List <MinigameBase>(gameNames.Length); foreach (string gameName in gameNames) { GameObject gameObj = null; int numCyclesToFindObj = 0; do { gameObj = GameObject.Find(gameName); if (gameObj != null) { break; } ++numCyclesToFindObj; yield return(new WaitForEndOfFrame()); } while (gameObj == null); print("find object (" + gameObj + ") with name " + gameName + " after " + numCyclesToFindObj + " cycles"); MinigameBase game = gameObj.GetComponent <MinigameBase>(); games.Add(game); game.PlayerIdx = games.IndexOf(game); } do { GameObject gameObj = GameObject.Find(metagameName); if (gameObj != null) { metagame = gameObj.GetComponent <MinigameBase>(); if (metagame != null) { print("found object (" + metagame + ") with name " + metagameName); break; } } yield return(new WaitForEndOfFrame()); } while (metagame == null); print("all games loaded"); gamesLoaded = true; foreach (MinigameBase game in games) { subscribeToGame(game); } randomizePlayersRoutine = randomizePlayersAfterDelay(); StartCoroutine(randomizePlayersRoutine); }
void onComboEventPassed(MinigameBase sender, Combo combo) { //Only pass combo events forward, don't wrap back to 1st game int gameIdx = games.IndexOf(sender); int nextGameIdx = gameIdx + 1; if (nextGameIdx < games.Count) { games[nextGameIdx].onCombo(combo); } else if (nextGameIdx == games.Count) { //Special case, pass to metagame metagame.onCombo(combo); } }
IEnumerator randomizePlayersAfterDelay() { do { if (!randomizePlayers) { yield break; } yield return(new WaitForSeconds((randomizePlayersDelayS - randomizeDelayAlertPreroll) * Time.timeScale)); if (InputSwapAlert) { InputSwapAlert.gameObject.SetActive(true); } yield return(new WaitForSeconds(randomizeDelayAlertPreroll * Time.timeScale)); if (InputSwapAlert) { InputSwapAlert.gameObject.SetActive(false); } //Shuffle PlayerIdx variables but not actual order in games array to keep input/outputs intact MinigameBase[] gamesTemp = games.ToArray(); if (gamesLoaded) { gamesTemp.Shuffle(); for (int i = 0; i < gamesTemp.Length; ++i) { MinigameBase game = gamesTemp[i]; game.PlayerIdx = i; } print(string.Format("Game inputs shuffled! new order = {0}", gamesTemp.toString())); } } while(true); }
void onComboEventFailed(MinigameBase sender, Combo combo) { print(string.Format("GameEventBus::onComboEventFailed: {0} from {1}", combo, sender.gameObject.name)); }