/// <summary>Get the signal that a listener at a given position would perceive</summary> /// <param name="listenerPosition">The listener's position in world space</param> /// <param name="use2D">True if distance calculation should ignore Z</param> /// <param name="pos">The position impulse signal</param> /// <param name="rot">The rotation impulse signal</param> /// <returns>true if non-trivial signal is returned</returns> public bool GetDecayedSignal( Vector3 listenerPosition, bool use2D, out Vector3 pos, out Quaternion rot) { if (m_SignalSource != null) { float distance = use2D ? Vector2.Distance(listenerPosition, m_Position) : Vector3.Distance(listenerPosition, m_Position); float time = Instance.CurrentTime - m_StartTime - distance / Mathf.Max(1, m_PropagationSpeed); float scale = m_Envelope.GetValueAt(time) * DistanceDecay(distance); if (scale != 0) { m_SignalSource.GetSignal(time, out pos, out rot); pos *= scale; rot = Quaternion.SlerpUnclamped(Quaternion.identity, rot, scale); if (m_DirectionMode == DirectionMode.RotateTowardSource && distance > Epsilon) { Quaternion q = Quaternion.FromToRotation(Vector3.up, listenerPosition - m_Position); if (m_Radius > Epsilon) { float t = Mathf.Clamp01(distance / m_Radius); q = Quaternion.Slerp( q, Quaternion.identity, Mathf.Cos(Mathf.PI * t / 2)); } pos = q * pos; } return(true); } } pos = Vector3.zero; rot = Quaternion.identity; return(false); }
/// <summary>Get the signal that a listener at a given position would perceive</summary> /// <param name="pos">The position impulse signal</param> /// <param name="rot">The rotation impulse signal</param> /// <returns>true if non-trivial signal is returned</returns> public bool GetDecayedSignal(Vector3 listenerPosition, out Vector3 pos, out Quaternion rot) { if (m_SignalSource != null) { float time = Time.time - m_StartTime; float distance = Vector3.Distance(listenerPosition, m_Position); float scale = m_Envelope.GetValueAt(time) * DistanceDecay(distance); m_SignalSource.GetSignal(time, out pos, out rot); pos *= scale; rot = Quaternion.SlerpUnclamped(Quaternion.identity, rot, scale); return(true); } pos = Vector3.zero; rot = Quaternion.identity; return(false); }