namespace VRTK.Prefabs.Helpers.TrackedCollider
{
using UnityEngine;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Zinnia.Extension;
using Zinnia.Data.Attribute;
using Zinnia.Tracking.Follow;
using Zinnia.Data.Operation.Extraction;
///
/// Sets up the TrackedCollider prefab based on the provided settings and implements the logic to follow the relevant source.
///
public class TrackedColliderConfigurator : MonoBehaviour
{
#region Facade Settings
///
/// The public interface facade.
///
[Serialized]
[field: Header("Facade Settings"), DocumentedByXml, Restricted]
public TrackedColliderFacade Facade { get; protected set; }
#endregion
#region Reference Settings
///
/// The that performs the source follow.
///
[Serialized]
[field: Header("Reference Settings"), DocumentedByXml, Restricted]
public ObjectFollower ObjectFollower { get; protected set; }
///
/// The that extracts the source position.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public TransformPositionExtractor PositionExtractor { get; protected set; }
#endregion
///
/// Sets the source on the relevant references.
///
/// The source to set.
public virtual void SetSource(GameObject source)
{
ObjectFollower.Sources.RunWhenActiveAndEnabled(() => ObjectFollower.Sources.Clear());
ObjectFollower.Sources.RunWhenActiveAndEnabled(() => ObjectFollower.Sources.Add(source));
PositionExtractor.Source = source;
}
///
/// Snaps the tracked collider directly to the source current position.
///
public virtual void SnapToSource()
{
PositionExtractor.DoExtract();
}
protected virtual void OnEnable()
{
SetSource(Facade.Source);
}
}
}