brunomikoski / Animation-Sequencer

A visual tool that allows you to create animated sequences of tweens and tweak them on editor time.
MIT License
960 stars 116 forks source link

Play sequence backwards. #32

Closed BruceKristelijn closed 2 years ago

BruceKristelijn commented 2 years ago

What's the best way to revert the sequence in code? I currently have a pretty weird setup: ` public override void StartTransition(int direction, Callback callback, RectTransform targetTransform) { this.direction = direction; sequencerController = targetTransform.GetComponent();

        targetTransform.gameObject.SetActive(true);
        if (direction == 1)
        {
            SetForwardBackward(0);
            sequencerController.GenerateSequence();
            sequencerController.Play();
            sequencerController.PlayingSequence.SetAutoKill(false);
        }
        else
        {
            SetForwardBackward(1);
            sequencerController.Kill();
            sequencerController.Play();
            sequencerController.PlayingSequence.Goto(1 * sequencerController.PlayingSequence.Duration());
            sequencerController.PlayingSequence.Play();
        }
    }

    private void SetForwardBackward(int enumint)
    {
        var enumtype = typeof(AnimationSequencerController).Assembly.GetType("BrunoMikoski.AnimationSequencer.AnimationSequencerController+PlayType");
        var newenum = Enum.ToObject(enumtype, enumint);
        var prop = typeof(AnimationSequencerController).GetField("playType", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        prop.SetValue(sequencerController, newenum);
    }`

It works but there's probably a better way isn't there?

brunomikoski commented 2 years ago

You could just change the direction on the editor right?

image

I'm exposing this to be called by code as well on the next version

brunomikoski commented 2 years ago

Implemented on the release