namespace Zinnia.Tracking.Follow.Modifier.Property
{
using UnityEngine;
using Zinnia.Extension;
using Zinnia.Tracking.Follow;
///
/// Modifies a specific property.
///
public abstract class PropertyModifier : MonoBehaviour
{
#region Modifier Events
///
/// Emitted before the property is modified.
///
[Header("Modifier Events")]
public ObjectFollower.FollowEvent Premodified = new ObjectFollower.FollowEvent();
///
/// Emitted after the property is modified.
///
public ObjectFollower.FollowEvent Modified = new ObjectFollower.FollowEvent();
#endregion
#region Modifier Settings
[Header("Modifier Settings")]
[Tooltip("Determines whether the offset will be applied on the modification.")]
[SerializeField]
private bool applyOffset = true;
///
/// Determines whether the offset will be applied on the modification.
///
public bool ApplyOffset
{
get
{
return applyOffset;
}
set
{
applyOffset = value;
}
}
#endregion
///
/// The event data to emit before and after the property has been modified.
///
protected readonly ObjectFollower.EventData eventData = new ObjectFollower.EventData();
///
/// Attempts to modify the target.
///
/// Event data that contains the required modifier properties.
public virtual void Modifiy(ObjectFollower.EventData data)
{
if (!this.IsValidState())
{
return;
}
Modify(data.EventSource, data.EventTarget, data.EventTargetOffset);
}
///
/// Attempts modify the target.
///
/// The source to utilize in the modification.
/// The target to modify.
/// The offset of the target against the source when modifying.
public virtual void Modify(GameObject source, GameObject target, GameObject offset = null)
{
if (!this.IsValidState() || source == null || target == null)
{
return;
}
offset = ApplyOffset ? offset : null;
Premodified?.Invoke(eventData.Set(source, target, offset));
DoModify(source, target, offset);
Modified?.Invoke(eventData.Set(source, target, offset));
}
///
/// Attempts modify the target.
///
/// The source to utilize in the modification.
/// The target to modify.
/// The offset of the target against the source when modifying.
protected abstract void DoModify(GameObject source, GameObject target, GameObject offset = null);
}
}