public static AudioEvent StopEvent(string name) { AudioEvent e = GetEvent(name); e.Stop(); return(e); }
void rbMotor() { if (rb == null) { return; } if (Mathf.Approximately(_forwardDrive, 0)) { if (motorOn && motorSfx != null) { motorSfx.Stop(AudioManager.GetInstance().GetEmitter(rootGo, motorSfx)); } motorOn = false; return; } if (!motorOn && motorSfx != null) { //motorSfx.Play(audio); motorSfx.Play(AudioManager.GetInstance().GetEmitter(rootGo, motorSfx)); } motorOn = true; var f = maxTorque * _forwardDrive; if (reverse) { f = -f; } rb.maxAngularVelocity = maxSpeed; rb.AddTorque(transform.right * f); }
public virtual void Play(bool oneShot = false) { if (stopEventOnPlay != null) { stopEventOnPlay.Stop(); } if (source == null) { if (VERBOSE) { Debug.Log($"AudioEvent: Tried to play {name} with source equal to null."); } return; } if (source.clip == null) { if (VERBOSE) { Debug.Log($"AudioEvent: Tried to play {name} with audioClip equal to null."); } return; } // Check if AudioSource is active and check cooldown time if (!source.gameObject.activeSelf) { return; } if (Time.time < nextAvailablePlayTime) { return; } source.clip = clips[clipIndex]; source.pitch = pitch + Random.Range(0f, randomPitch) - (randomPitch * 0.5f); // Play if (oneShot) { source.PlayOneShot(source.clip); } else { source.Play(); } lastPlayedIndex = clipIndex; RandomizeIndex(); lastPlayedTime = Time.time; nextAvailablePlayTime = lastPlayedTime + cooldownSeconds; OnPlay?.Invoke(); }
IEnumerator StateMatchPlay() { if (debug) { Debug.Log("StateMatchPlay"); } // stop the main music track if (mainMusicTrack != null) { mainMusicTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, mainMusicTrack)); } // store current player/match info into shared GameInfo gameInfo.playerInfo = playerInfo; gameInfo.matchInfo = matchInfo; // load the arena SceneManager.LoadScene(arenaScene); yield return(null); // Start the match wantMatchStart.Raise(); // wait for match to finish var done = false; var listener = gameObject.AddComponent <GameEventListener>(); listener.SetEvent(matchFinished); listener.Response.AddListener(() => { done = true; }); yield return(new WaitUntil(() => done)); // stop the match scene, reload main menu scene SceneManager.LoadScene(mainScene); yield return(null); // restart main music track if (mainMusicTrack != null) { mainMusicTrack.Play(AudioManager.GetInstance().GetEmitter(gameObject, mainMusicTrack)); } // transition back to match select StartCoroutine(StateMatchSelect()); }
IEnumerator StateAnnouncer() { if (debug) { Debug.Log("StateAnnouncer"); } // start announcer music if (announcerTrack != null) { announcerTrack.Play(AudioManager.GetInstance().GetEmitter(gameObject, announcerTrack)); } // enable announcer camera mode if (cameraController != null) { cameraController.WatchAnnouncer(); } if (bannerFade != null) { bannerMessage.Raise("ANNOUNCER INTRO - ESC TO EXIT"); } // FIXME: remove announcer timer yield return(StartCoroutine(RunTimer(5, null, () => (!Input.GetKeyUp(KeyCode.Escape))))); // TODO: add announcer voiceover mechanics/state if (announcerTrack != null) { announcerTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, announcerTrack)); } // TRANSITION: Countdown StartCoroutine(StateCountdown()); }
IEnumerator StateFinish() { if (debug) { Debug.Log("StateFinish"); } // notify channel if (gameEventChannel != null) { gameEventChannel.Raise(GameRecord.GameFinished()); } // declare game over if (bannerMessage != null) { bannerMessage.Raise("Game Over!!!"); } yield return(null); // disable bots for (var i = allBots.Items.Count - 1; i >= 0; i--) { allBots.Items[i].GetComponent <BotBrain>().DisableControls(); } // stop match music if (gameInfo.matchInfo.matchMusicTrack != null) { gameInfo.matchInfo.matchMusicTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, gameInfo.matchInfo.matchMusicTrack)); } // add win/loss for player if (winningBot == spawnedPlayer) { // create score for win var scoreInfo = new MatchScoreInfo(); scoreInfo.matchID = gameInfo.matchInfo.id; scoreInfo.time = timerTick; scoreInfo.score = scoreKeeper.GetScore(); gameInfo.playerInfo.AddWin(scoreInfo); // update scoreboard var json = JsonStore.Load(JsonStore.SaveTag.Score, gameInfo.matchInfo.id); var scoreboard = MatchScoreboard.FromJson(json); if (scoreboard == null) { scoreboard = new MatchScoreboard(gameInfo.matchInfo.id); } scoreboard.AddScore(gameInfo.playerInfo.name, scoreInfo.score, scoreInfo.time); } else { gameInfo.playerInfo.AddLoss(); } // start win/loss music if (winLossTrack != null) { winLossTrack.Play(AudioManager.GetInstance().GetEmitter(gameObject, winLossTrack)); } // setup listener for doneConfirmed event var confirmed = false; var listener = gameObject.AddComponent <GameEventListener>(); listener.SetEvent(doneConfirmed); listener.Response.AddListener(() => { confirmed = true; }); // instantiate modal for confirmation var panelGo = Instantiate(donePanelPrefab, GetCanvas().gameObject.transform); yield return(null); // wait a frame for panel initialization // trigger event to notify player that match is complete, // causes confirmation modal to display message and wait for player to click ok var msg = System.String.Format("{0}:{1}", (winningBot == spawnedPlayer) ? "win" : "loss", gameInfo.playerInfo.name); wantDoneConfirm.Raise(msg); // wait for match info to be selected yield return(new WaitUntil(() => confirmed)); if (winLossTrack != null) { winLossTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, winLossTrack)); } // clean up, remove listener Destroy(panelGo); Destroy(listener); // signal that the match is done if (matchFinished != null) { matchFinished.Raise(); } }