KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
65 stars 8 forks source link

How to register a custom class so it shows with [SerializeReference] ITransition? #260

Closed ADH-LukeBollam closed 1 year ago

ADH-LukeBollam commented 1 year ago

I've created a custom class with a bit more configuration for an animation

public class DetailedTransition : ClipTransition, ITransitionDetailed, IPolymorphic
{
    [SerializeField] private float _playbackWeight;
    [SerializeField] private bool _applyRootMotion;

    public override void Apply(AnimancerState state)
    {
        base.Apply(state);
        state.Root.Component.Animator.applyRootMotion = _applyRootMotion;

        // if the layer weight is 0, fade in to target weight
        if (state.Layer.Weight == 0)
        {
            state.Layer.StartFade(_playbackWeight, FadeDuration);
        }
    }
}

And a container for them

[Serializable] public class AnimationConfiguration
{
    [SerializeReference] List<ITransitionDetailed> _clips;
    public ReadOnlyCollection<ITransitionDetailed> Clips { get { return _clips.AsReadOnly(); } }
}

However the inspector doesn't show my class as an option in the dropdown, what do I need to do to get it registered?

Cheers.

ADH-LukeBollam commented 1 year ago

Nevermind, I was missing [Serializable] on my class 🤦‍♂️