namespace Zinnia.Cast.Operation.Mutation
{
using UnityEngine;
using Zinnia.Extension;
using Zinnia.Rule;
///
/// Mutates the properties of a with the benefit of being able to specify a containing as the target.
///
public class PointsCastPropertyMutator : MonoBehaviour
{
[Tooltip("The PointsCast to mutate.")]
[SerializeField]
private PointsCast target;
///
/// The to mutate.
///
public PointsCast Target
{
get
{
return target;
}
set
{
target = value;
}
}
///
/// The origin point for the cast.
///
private GameObject origin;
public GameObject Origin
{
get
{
return origin;
}
set
{
origin = value;
if (this.IsMemberChangeAllowed())
{
OnAfterOriginChange();
}
}
}
///
/// Optionally affects the cast.
///
private PhysicsCast physicsCast;
public PhysicsCast PhysicsCast
{
get
{
return physicsCast;
}
set
{
physicsCast = value;
if (this.IsMemberChangeAllowed())
{
OnAfterPhysicsCastChange();
}
}
}
///
/// Optionally determines targets based on the set rules.
///
private RuleContainer targetValidity;
public RuleContainer TargetValidity
{
get
{
return targetValidity;
}
set
{
targetValidity = value;
if (this.IsMemberChangeAllowed())
{
OnAfterTargetValidityChange();
}
}
}
///
/// An override for the destination location point in world space.
///
private Vector3? destinationPointOverride;
public Vector3? DestinationPointOverride
{
get
{
return destinationPointOverride;
}
protected set
{
destinationPointOverride = value;
if (this.IsMemberChangeAllowed())
{
OnAfterDestinationPointOverrideChange();
}
}
}
///
/// Clears .
///
public virtual void ClearTarget()
{
if (!this.IsValidState())
{
return;
}
Target = default;
}
///
/// Clears .
///
public virtual void ClearOrigin()
{
if (!this.IsValidState())
{
return;
}
Origin = default;
}
///
/// Clears .
///
public virtual void ClearPhysicsCast()
{
if (!this.IsValidState())
{
return;
}
PhysicsCast = default;
}
///
/// Clears .
///
public virtual void ClearTargetValidity()
{
if (!this.IsValidState())
{
return;
}
TargetValidity = default;
}
///
/// Sets the based on the first found as either a direct, descendant or ancestor of the given .
///
/// The to search for a on.
public virtual void SetTarget(GameObject target)
{
if (!this.IsValidState() || target == null)
{
return;
}
Target = target.TryGetComponent(true, true);
}
///
/// Sets the from a .
///
/// The new value.
public virtual void SetDestinationPointOverride(Vector3 destinationPointOverride)
{
DestinationPointOverride = destinationPointOverride;
}
///
/// Clears the .
///
public virtual void ClearDestinationPointOverride()
{
if (!this.IsValidState() || Target == null)
{
return;
}
DestinationPointOverride = default;
Target.ClearDestinationPointOverride();
}
///
/// Called after has been changed.
///
protected virtual void OnAfterOriginChange()
{
if (Target == null)
{
return;
}
Target.Origin = Origin;
}
///
/// Called after has been changed.
///
protected virtual void OnAfterPhysicsCastChange()
{
if (Target == null)
{
return;
}
Target.PhysicsCast = PhysicsCast;
}
///
/// Called after has been changed.
///
protected virtual void OnAfterTargetValidityChange()
{
if (Target == null)
{
return;
}
Target.TargetValidity = TargetValidity;
}
///
/// Called after has been changed.
///
protected virtual void OnAfterDestinationPointOverrideChange()
{
if (Target == null)
{
return;
}
Target.DestinationPointOverride = DestinationPointOverride;
}
}
}