namespace Tilia.Trackers.ColliderFollower
{
using UnityEngine;
using Zinnia.Data.Attribute;
using Zinnia.Data.Operation.Extraction;
using Zinnia.Extension;
using Zinnia.Tracking.Follow;
///
/// Sets up the ColliderFollower prefab based on the provided settings and implements the logic to follow the relevant source.
///
public class ColliderFollowerConfigurator : MonoBehaviour
{
#region Facade Settings
[Header("Facade Settings")]
[Tooltip("The public interface facade.")]
[SerializeField]
[Restricted]
private ColliderFollowerFacade facade;
///
/// The public interface facade.
///
public ColliderFollowerFacade Facade
{
get
{
return facade;
}
protected set
{
facade = value;
}
}
#endregion
#region Reference Settings
[Header("Reference Settings")]
[Tooltip("The Zinnia.Tracking.Follow.ObjectFollower that performs the source follow.")]
[SerializeField]
[Restricted]
private ObjectFollower objectFollower;
///
/// The that performs the source follow.
///
public ObjectFollower ObjectFollower
{
get
{
return objectFollower;
}
protected set
{
objectFollower = value;
}
}
[Tooltip("The TransformPositionExtractor that extracts the source position.")]
[SerializeField]
[Restricted]
private TransformPositionExtractor positionExtractor;
///
/// The that extracts the source position.
///
public TransformPositionExtractor PositionExtractor
{
get
{
return positionExtractor;
}
protected set
{
positionExtractor = value;
}
}
[Tooltip("The TransformEulerRotationExtractor that extracts the source rotation.")]
[SerializeField]
[Restricted]
private TransformEulerRotationExtractor rotationExtractor;
///
/// The that extracts the source rotation.
///
public TransformEulerRotationExtractor RotationExtractor
{
get
{
return rotationExtractor;
}
protected set
{
rotationExtractor = value;
}
}
[Tooltip("The GameObject containing the collider.")]
[SerializeField]
[Restricted]
private GameObject colliderContainer;
///
/// The containing the collider.
///
public GameObject ColliderContainer
{
get
{
return colliderContainer;
}
protected set
{
colliderContainer = value;
}
}
#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;
RotationExtractor.Source = source;
}
///
/// Snaps the tracked collider directly to the source current position.
///
public virtual void SnapToSource()
{
PositionExtractor.DoExtract();
RotationExtractor.DoExtract();
}
protected virtual void OnEnable()
{
SetSource(Facade.Source);
if (Facade.SnapOnEnable)
{
SnapToSource();
}
}
}
}