namespace UnityEngine.Animations.Rigging { /// /// Use this class to define an override rig constraint on another rig constraint. /// While the overriden constraint data remains the same, the job is overriden. /// /// The base constraint to override /// The override job /// The constraint data /// The override constraint job binder public class OverrideRigConstraint : IRigConstraint where TConstraint : MonoBehaviour, IRigConstraint where TJob : struct, IWeightedAnimationJob where TData : struct, IAnimationJobData where TBinder : AnimationJobBinder, new() { /// /// The base constraint. /// [SerializeField] protected TConstraint m_Constraint; static readonly TBinder s_Binder = new TBinder(); /// /// Constructor /// /// The constraint to override. public OverrideRigConstraint(TConstraint baseConstraint) { m_Constraint = baseConstraint; } /// /// Creates the animation job for this constraint. /// /// The animated hierarchy Animator component. /// Returns the newly instantiated job. public IAnimationJob CreateJob(Animator animator) { IAnimationJobBinder binder = (IAnimationJobBinder)s_Binder; TJob job = (TJob)binder.Create(animator, m_Constraint.data, m_Constraint); // Bind constraint job weight property job.jobWeight = FloatProperty.BindCustom( animator, ConstraintsUtils.ConstructCustomPropertyName(m_Constraint, ConstraintProperties.s_Weight) ); return job; } /// /// Frees the specified job memory. /// /// public void DestroyJob(IAnimationJob job) => s_Binder.Destroy((TJob)job); /// /// Updates the specified job data. /// /// public void UpdateJob(IAnimationJob job) { IAnimationJobBinder binder = (IAnimationJobBinder)s_Binder; binder.Update(job, m_Constraint.data); } /// /// Retrieves the constraint valid state. /// /// Returns true if constraint data can be successfully evaluated. Returns false otherwise. public bool IsValid() { return m_Constraint.IsValid(); } /// /// The job binder for the constraint. /// IAnimationJobBinder IRigConstraint.binder => s_Binder; /// /// The data container for the constraint. /// IAnimationJobData IRigConstraint.data => m_Constraint.data; /// /// The component for the constraint. /// Component IRigConstraint.component => m_Constraint.component; /// /// The constraint weight. This is a value between 0 and 1. /// public float weight { get => m_Constraint.weight; set => m_Constraint.weight = value; } } }