namespace Zinnia.Data.Operation.Extraction
{
using UnityEngine;
using Zinnia.Extension;
///
/// Extracts a chosen axis of a .
///
public class TransformDirectionExtractor : TransformVector3PropertyExtractor
{
///
/// The direction axes of the transform.
///
public enum AxisDirection
{
///
/// The axis moving right from the transform origin.
///
Right,
///
/// The axis moving up from the transform origin.
///
Up,
///
/// The axis moving forward from the transform origin.
///
Forward
}
[Tooltip("The direction to extract from the Transform.")]
[SerializeField]
private AxisDirection direction;
///
/// The direction to extract from the .
///
public AxisDirection Direction
{
get
{
return direction;
}
set
{
direction = value;
}
}
///
/// Sets the .
///
/// The index of the .
public virtual void SetDirection(int index)
{
Direction = EnumExtensions.GetByIndex(index);
}
///
protected override Vector3? ExtractValue()
{
if (Source == null)
{
return null;
}
switch (Direction)
{
case AxisDirection.Right:
return UseLocal ? Source.transform.localRotation * Vector3.right : Source.transform.right;
case AxisDirection.Up:
return UseLocal ? Source.transform.localRotation * Vector3.up : Source.transform.up;
case AxisDirection.Forward:
return UseLocal ? Source.transform.localRotation * Vector3.forward : Source.transform.forward;
}
return Vector3.zero;
}
}
}