using System.Collections; using UnityEngine; namespace Invector.vCharacterController.AI { /// /// Noise Object is used to shoot "sounds" that can be detected by the Controller a through the /// [System.Serializable] public class vNoise { [System.Serializable] public class vAINoiseEvent : UnityEngine.Events.UnityEvent { } public vNoise(string noiseType,Vector3 position,float volume,float minDistance,float maxDistance,float duration) { this.noiseType = noiseType; this.position = position; this.volume = volume; this.minDistance = minDistance; this.maxDistance = maxDistance; this.duration = duration; AddDuration(duration); } public bool isPlaying;// { get; protected set; } public vAINoiseEvent onFinishNoise = new vAINoiseEvent(); public float duration; /// /// Add more time to noise finish /// /// public void AddDuration(float duration) { noiseFinishTime = Time.time + duration; } /// /// Remove duraction of the noise /// public void CancelNoise() { noiseFinishTime = 0; } /// /// Coroutine to control when the noise will finish /// /// noise finish callback /// public IEnumerator Play() { if (!isPlaying) { AddDuration(duration); isPlaying = true; while (noiseFinishTime > Time.time) yield return null; isPlaying = false; if (onFinishNoise != null) onFinishNoise.Invoke(this); } } /// /// The center of the noise /// public Vector3 position; /// /// The type of noise. Can be used by to make different decisions /// public string noiseType; /// /// maximum volume that noise produces /// public float volume; /// /// Minimun distance that the noise can be heard /// public float minDistance; /// /// maximum distance that the noise can be heard /// public float maxDistance; float noiseFinishTime; } }