namespace Zinnia.Tracking.Velocity
{
using UnityEngine;
using Zinnia.Tracking.Velocity.Collection;
///
/// Processes the first active found in the given .
///
public class VelocityTrackerProcessor : VelocityTracker
{
[Tooltip("The VelocityTracker collection to attempt to process.")]
[SerializeField]
private VelocityTrackerObservableList velocityTrackers;
///
/// The collection to attempt to process.
///
public VelocityTrackerObservableList VelocityTrackers
{
get
{
return velocityTrackers;
}
set
{
velocityTrackers = value;
}
}
///
/// The current active that is reporting velocities.
///
public virtual VelocityTracker ActiveVelocityTracker
{
get => activeVelocityTracker != null && activeVelocityTracker.IsActive() ? activeVelocityTracker : null;
protected set
{
activeVelocityTracker = value;
}
}
///
/// The backing field for holding the value of .
///
private VelocityTracker activeVelocityTracker;
///
/// The reported velocity on the first active .
///
/// The current velocity.
protected override Vector3 DoGetVelocity()
{
SetActiveVelocityTracker();
return ActiveVelocityTracker != null ? ActiveVelocityTracker.GetVelocity() : Vector3.zero;
}
///
/// The reported angular velocity on the first active .
///
/// The current angular velocity.
protected override Vector3 DoGetAngularVelocity()
{
SetActiveVelocityTracker();
return ActiveVelocityTracker != null ? ActiveVelocityTracker.GetAngularVelocity() : Vector3.zero;
}
///
/// Sets the active from the collection.
///
protected virtual void SetActiveVelocityTracker()
{
ActiveVelocityTracker = null;
if (VelocityTrackers == null)
{
return;
}
foreach (VelocityTracker tracker in VelocityTrackers.NonSubscribableElements)
{
if (tracker.IsActive())
{
ActiveVelocityTracker = tracker;
break;
}
}
}
}
}