using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations.Rigging;
namespace UnityEditor.Animations.Rigging
{
///
/// Attribute that can be placed on BakeParameters. The attribute is used to declare to which RigConstraint the BakeParameters belong.
///
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class BakeParametersAttribute : Attribute
{
///
/// Constructor.
///
/// The RigConstraint to which the BakeParameters belong.
public BakeParametersAttribute(Type constraintType)
{
if (constraintType == null || !typeof(IRigConstraint).IsAssignableFrom(constraintType))
Debug.LogError("Invalid constraint for InverseRigConstraint attribute.");
this.constraintType = constraintType;
}
///
/// The RigConstraint to which the BakeParameters belong.
///
public Type constraintType { get; }
}
///
/// Class that holds bi-directional baking capabilities and curve bindings of a RigConstraint.
///
/// The Type of RigConstraint the parameters belong to.
public abstract class BakeParameters : IBakeParameters
where T : IRigConstraint
{
///
/// Boolean used to determine if the RigConstraint can transfer motion from itself to the skeleton
///
public abstract bool canBakeToSkeleton { get; }
///
/// Boolean used to determine if the RigConstraint can transfer motion to itself from the skeleton.
///
public abstract bool canBakeToConstraint { get; }
///
/// Collects the editor curve bindings for all the properties that this RigConstraint modifies when transferring motion to the skeleton.
///
/// The RigBuilder which the constraint is part of.
/// The RigConstraint for which the bindings should be collected.
///
public abstract IEnumerable GetSourceCurveBindings(RigBuilder rigBuilder, T constraint);
///
/// Collects the editor curve bindings for all the properties that this RigConstraint modifies when transferring motion to this constraint.
///
/// The RigBuilder which the constraint is part of.
/// The RigConstraint for which the bindings should be collected.
///
public abstract IEnumerable GetConstrainedCurveBindings(RigBuilder rigBuilder, T constraint);
///
bool IBakeParameters.canBakeToSkeleton => canBakeToSkeleton;
///
bool IBakeParameters.canBakeToConstraint => canBakeToConstraint;
///
IEnumerable IBakeParameters.GetSourceCurveBindings(RigBuilder rigBuilder, IRigConstraint constraint)
{
Debug.Assert(constraint is T);
T tConstraint = (T)constraint;
return GetSourceCurveBindings(rigBuilder, tConstraint);
}
///
IEnumerable IBakeParameters.GetConstrainedCurveBindings(RigBuilder rigBuilder, IRigConstraint constraint)
{
Debug.Assert(constraint is T);
T tConstraint = (T)constraint;
return GetConstrainedCurveBindings(rigBuilder, tConstraint);
}
}
///
/// This is the base interface for BakeParameters.
///
public interface IBakeParameters
{
///
/// Boolean used to determine if the RigConstraint can transfer motion from itself to the skeleton
///
bool canBakeToSkeleton { get; }
///
/// Boolean used to determine if the RigConstraint can transfer motion to itself from the skeleton.
///
bool canBakeToConstraint { get; }
///
/// Collects the editor curve bindings for all the properties that this RigConstraint modifies when transferring motion to the skeleton.
///
/// The RigBuilder which the constraint is part of.
/// The RigConstraint for which the bindings should be collected.
///
IEnumerable GetSourceCurveBindings(RigBuilder rigBuilder, IRigConstraint constraint);
///
/// Collects the editor curve bindings for all the properties that this RigConstraint modifies when transferring motion to this constraint.
///
/// The RigBuilder which the constraint is part of.
/// The RigConstraint for which the bindings should be collected.
///
IEnumerable GetConstrainedCurveBindings(RigBuilder rigBuilder, IRigConstraint constraint);
}
}