/// <summary> /// Get sound source from collections /// </summary> /// <param name="sound"></param> /// <param name="parent"></param> /// <param name="position"></param> /// <returns></returns> private SoundSource GetSoundSource(Sound sound, Transform parent, Vector3 position) { SoundSource source = null; if (!parent) { parent = transform; } switch (sound.type) { case SoundType.Effect: case SoundType.Music: case SoundType.Speech: if (sources.FindAll(s => { return(s.name == sound.name); }).Count <= sound.instanceLimit) { source = ObjectPool.Request <SoundSource>(soundSourcePrefab, parent, position, Quaternion.identity); source.StopEvent += OnSoundSourceStop; } break; } if (source) { switch (sound.type) { case SoundType.Effect: source.GetComponent <AudioSource> ().outputAudioMixerGroup = effectsGroup; break; case SoundType.Speech: source.GetComponent <AudioSource> ().outputAudioMixerGroup = voicesGroup; break; case SoundType.Music: source.GetComponent <AudioSource> ().outputAudioMixerGroup = musicGroup; break; } sources.Add(source); } return(source); }
/// <summary> /// Play sound source of given sound /// </summary> /// <param name="sound"></param> /// <param name="fadeTime"></param> /// <param name="parent"></param> /// <param name="position"></param> /// <returns></returns> public SoundSource Play(Sound sound, float fadeTime = 0f, Transform parent = null, Vector3 position = default(Vector3)) { if (sound == null) { return(null); } Initialize(sound, fadeTime); SoundSource source = GetSoundSource(sound, parent, position); //source.SetVolumeTo(sound.volume, 0); if (source) { source.Play(sound, fadeTime); } else { Debug.LogError("source is null!"); } return(source); }
private void FixedUpdate() { if(CachedPlayerStats.CurrentMovementSpeed > 0) { if (carController.MaxSpeed != playerStats.CurrentMovementSpeed) carController.MaxSpeed = playerStats.CurrentMovementSpeed; float h = 0; float v = CrossPlatformInputManager.GetAxis("Vertical"); float handbrake = CrossPlatformInputManager.GetAxis("Jump"); if (v != 0) { h = CrossPlatformInputManager.GetAxis("Horizontal"); if (cachedSoundSource == null) cachedSoundSource = CachedSoundManager.Play(CurrentMovementClip); } else if (CrossPlatformInputManager.GetAxis("Horizontal") != 0) { float rotationAngle = CachedPlayerStats.MovementSpeed * movementSpeedMultiplier * Time.deltaTime * CrossPlatformInputManager.GetAxis("Horizontal"); transform.Rotate(Vector3.up, rotationAngle); if (cachedSoundSource == null) cachedSoundSource = CachedSoundManager.Play(CurrentMovementClip); } else { if (cachedSoundSource != null) { CachedSoundManager.Play(CurrentStopClip); CachedSoundManager.Stop(cachedSoundSource); } } if (mouseLook.rotationX != 0 && h == 0 && v != 0) { //if the camera rotation is different than the chassi rotation and theres no horizontal input //then we want to turn anyway mouseLook.rotationX = Mathf.Lerp(mouseLook.rotationX, 0, Time.deltaTime); h = (mouseLook.rotationX / mouseLook.maximumX) * mouseLook.sensitivityX; } wheelAnimator.SetFloat("speed", v); handbrake = (v == 0 && handbrake == 0) ? 1 : 0; carController.Move(h, v, v, handbrake); } else { carController.Move(0, 0, 0, 1); if(cachedSoundSource != null) CachedSoundManager.Stop(cachedSoundSource); } }
/// <summary> /// Cleanup sound source /// </summary> /// <param name="source"></param> private void OnSoundSourceStop(SoundSource source) { source.StopEvent -= OnSoundSourceStop; sources.Remove(source); ObjectPool.Recycle(source.gameObject); }
/// <summary> /// Stop sound of given sound source /// </summary> /// <param name="soundSource"></param> public void Stop(SoundSource soundSource) { soundSource.Stop(); }
private void FixedUpdate() { if (CachedPlayerStats.CurrentMovementSpeed > 0) { if (carController.MaxSpeed != playerStats.CurrentMovementSpeed) { carController.MaxSpeed = playerStats.CurrentMovementSpeed; } float h = 0; float v = CrossPlatformInputManager.GetAxis("Vertical"); float handbrake = CrossPlatformInputManager.GetAxis("Jump"); if (v != 0) { h = CrossPlatformInputManager.GetAxis("Horizontal"); if (cachedSoundSource == null) { cachedSoundSource = CachedSoundManager.Play(CurrentMovementClip); } } else if (CrossPlatformInputManager.GetAxis("Horizontal") != 0) { float rotationAngle = CachedPlayerStats.MovementSpeed * movementSpeedMultiplier * Time.deltaTime * CrossPlatformInputManager.GetAxis("Horizontal"); transform.Rotate(Vector3.up, rotationAngle); if (cachedSoundSource == null) { cachedSoundSource = CachedSoundManager.Play(CurrentMovementClip); } } else { if (cachedSoundSource != null) { CachedSoundManager.Play(CurrentStopClip); CachedSoundManager.Stop(cachedSoundSource); } } if (mouseLook.rotationX != 0 && h == 0 && v != 0) { //if the camera rotation is different than the chassi rotation and theres no horizontal input //then we want to turn anyway mouseLook.rotationX = Mathf.Lerp(mouseLook.rotationX, 0, Time.deltaTime); h = (mouseLook.rotationX / mouseLook.maximumX) * mouseLook.sensitivityX; } wheelAnimator.SetFloat("speed", v); handbrake = (v == 0 && handbrake == 0) ? 1 : 0; carController.Move(h, v, v, handbrake); } else { carController.Move(0, 0, 0, 1); if (cachedSoundSource != null) { CachedSoundManager.Stop(cachedSoundSource); } } }
protected IEnumerator DisplayDialogueCoroutine(List <DisplayDialogue> displayTexts, QuestObjective qo, bool isHuman = true) { for (int i = 0; i < displayTexts.Count; i++) { qo.questTrigger.Initialize(); DisplayDialogue dd = displayTexts[i]; float delay = dd.displayText.Length * characterDelay; float desiredTime = delay; if (dd.clip != null) { desiredTime = dd.clip.length; delay = dd.clip.length; SoundSource ss = GameManager.Get <SoundManager>().Play(dd.clip); if (isHuman && radioAmg != null) { ss.cachedAudioSource.outputAudioMixerGroup = radioAmg; } if (!isHuman && aiAmg != null) { ss.cachedAudioSource.outputAudioMixerGroup = aiAmg; } } UIManager.GetMenu <ObjectiveTracker>().Open(dd.displayText, isHuman, true, delay); desiredTime += 0.75f; switch (dd.effect) { case Sol.DisplayDialogue.DisplayEffect.Glitch: StartCoroutine(GlitchOut(dd.duration)); break; case Sol.DisplayDialogue.DisplayEffect.FadeIn: UIManager.GetMenu <FadeMenu>().Fade(dd.duration, Color.black, Color.clear); break; case Sol.DisplayDialogue.DisplayEffect.FadeOut: UIManager.GetMenu <FadeMenu>().Fade(dd.duration, Color.clear, Color.black, true); break; case Sol.DisplayDialogue.DisplayEffect.None: default: break; } float elapsedTime = 0f; while (elapsedTime < desiredTime) { elapsedTime += Time.deltaTime; //if (GameManager.Get<QuestManager>().testMode && Input.GetKeyDown(KeyCode.Return)) break; yield return(null); } } while (!canProceed) { yield return(null); } CurrentQuest.CompleteObjective(endQuest, targetQuest); canProceed = false; }