namespace Zinnia.Tracking.Velocity { using UnityEngine; using Zinnia.Extension; /// /// Attempts to utilize the first found on the given proxy . /// public class ComponentTrackerProxy : VelocityTracker { [Tooltip("The GameObject that contains a VelocityTracker.")] [SerializeField] private GameObject proxySource; /// /// The that contains a . /// public GameObject ProxySource { get { return proxySource; } set { proxySource = value; if (this.IsMemberChangeAllowed()) { OnAfterProxySourceChange(); } } } /// /// The cached found on the proxy . /// protected VelocityTracker cachedVelocityTracker; /// /// Clears . /// public virtual void ClearProxySource() { if (!this.IsValidState()) { return; } ProxySource = default; } protected virtual void OnEnable() { SetCachedVelocityTracker(); } /// public override bool IsActive() { return base.IsActive() && cachedVelocityTracker != null && cachedVelocityTracker.CheckIsActiveAndEnabled(); } /// protected override Vector3 DoGetVelocity() { return cachedVelocityTracker.GetVelocity(); } /// protected override Vector3 DoGetAngularVelocity() { return cachedVelocityTracker.GetAngularVelocity(); } /// /// Called after has been changed. /// protected virtual void OnAfterProxySourceChange() { SetCachedVelocityTracker(); } /// /// Sets to the first found on the or any of its descendants. /// protected virtual void SetCachedVelocityTracker() { cachedVelocityTracker = ProxySource.TryGetComponent(true); } } }