using UnityEngine.Playables;
namespace UnityEngine.Animations.Rigging
{
///
/// This is the base interface for all animation job binders.
///
public interface IAnimationJobBinder
{
///
/// Creates the animation job.
///
/// The animated hierarchy Animator component.
/// The constraint data.
/// The constraint component.
/// Returns a new job interface.
IAnimationJob Create(Animator animator, IAnimationJobData data, Component component = null);
///
/// Destroys the animation job.
///
/// The animation job to destroy.
void Destroy(IAnimationJob job);
///
/// Updates the animation job.
///
/// The animation job to update.
/// The constraint data.
void Update(IAnimationJob job, IAnimationJobData data);
///
/// Creates an AnimationScriptPlayable with the specified animation job.
///
/// The PlayableGraph that will own the AnimationScriptPlayable.
/// The animation job to use in the AnimationScriptPlayable.
/// Returns a new AnimationScriptPlayable.
AnimationScriptPlayable CreatePlayable(PlayableGraph graph, IAnimationJob job);
}
///
/// The is the base class for all animation job binders.
///
/// The constraint job.
/// The constraint data.
public abstract class AnimationJobBinder : IAnimationJobBinder
where TJob : struct, IAnimationJob
where TData : struct, IAnimationJobData
{
///
/// Creates the animation job.
///
/// The animated hierarchy Animator component.
/// The constraint data.
/// The constraint component.
/// Returns a new job interface.
public abstract TJob Create(Animator animator, ref TData data, Component component);
///
/// Destroys the animation job.
///
/// The animation job to destroy.
public abstract void Destroy(TJob job);
///
/// Updates the animation job.
///
/// The animation job to update.
/// The constraint data.
public virtual void Update(TJob job, ref TData data) {}
///
IAnimationJob IAnimationJobBinder.Create(Animator animator, IAnimationJobData data, Component component)
{
Debug.Assert(data is TData);
TData tData = (TData)data;
return Create(animator, ref tData, component);
}
///
void IAnimationJobBinder.Destroy(IAnimationJob job)
{
Debug.Assert(job is TJob);
Destroy((TJob)job);
}
///
void IAnimationJobBinder.Update(IAnimationJob job, IAnimationJobData data)
{
Debug.Assert(data is TData && job is TJob);
TData tData = (TData)data;
Update((TJob)job, ref tData);
}
///
AnimationScriptPlayable IAnimationJobBinder.CreatePlayable(PlayableGraph graph, IAnimationJob job)
{
Debug.Assert(job is TJob);
return AnimationScriptPlayable.Create(graph, (TJob)job);
}
}
}