namespace Zinnia.Tracking.Velocity { using System; using UnityEngine; using UnityEngine.Events; using Zinnia.Extension; /// /// Emits the velocities of a given . /// public class VelocityEmitter : MonoBehaviour { /// /// Defines the event with the . /// [Serializable] public class Vector3UnityEvent : UnityEvent { } /// /// Defines the event with the . /// [Serializable] public class FloatUnityEvent : UnityEvent { } [Tooltip("The source VelocityTracker to receive the velocity data from.")] [SerializeField] private VelocityTracker source; /// /// The source to receive the velocity data from. /// public VelocityTracker Source { get { return source; } set { source = value; } } /// /// Emitted when the Tracked Velocity is emitted. /// public Vector3UnityEvent VelocityEmitted = new Vector3UnityEvent(); /// /// Emitted when the Tracked Speed is emitted. /// public FloatUnityEvent SpeedEmitted = new FloatUnityEvent(); /// /// Emitted when the Tracked Angular Velocity is emitted. /// public Vector3UnityEvent AngularVelocityEmitted = new Vector3UnityEvent(); /// /// Emitted when the Tracked Angular Speed is emitted. /// public FloatUnityEvent AngularSpeedEmitted = new FloatUnityEvent(); /// /// Clears . /// public virtual void ClearSource() { if (!this.IsValidState()) { return; } Source = default; } /// /// Emits the Velocity of the Tracked Velocity. /// public virtual void EmitVelocity() { if (!this.IsValidState() || Source == null) { return; } VelocityEmitted?.Invoke(Source.GetVelocity()); } /// /// Emits the Speed of the Tracked Velocity. /// public virtual void EmitSpeed() { if (!this.IsValidState() || Source == null) { return; } SpeedEmitted?.Invoke(Source.GetVelocity().magnitude); } /// /// Emits the Angular Velocity of the Tracked Velocity. /// public virtual void EmitAngularVelocity() { if (!this.IsValidState() || Source == null) { return; } AngularVelocityEmitted?.Invoke(Source.GetAngularVelocity()); } /// /// Emits the Angular Velocity of the Tracked Velocity. /// public virtual void EmitAngularSpeed() { if (!this.IsValidState() || Source == null) { return; } AngularSpeedEmitted?.Invoke(Source.GetAngularVelocity().magnitude); } /// /// Emits the Velocity, Speed, Angular Velocity and Angular Speed of the Tracked Velocity. /// public virtual void EmitAll() { EmitVelocity(); EmitSpeed(); EmitAngularVelocity(); EmitAngularSpeed(); } } }