DhafinFawwaz / Unity-AnimationUI

Usefull Unity tool for animating UI with just drag and drop
MIT License
360 stars 35 forks source link

Object motion callbacks added #3

Open QQ1273459693 opened 6 months ago

QQ1273459693 commented 6 months ago

It would be perfect if you could implement a callback after each movement, e.g., after object A moves to position B, I'll move A to position C again, and then I'll call the callback after each movement.

DhafinFawwaz commented 6 months ago

Try this Callback in AnimationUI

Bassically its:

  1. Move transform A From position A to potition B for x seconds
  2. Wait x seconds
  3. Call unityevent
  4. Move transform A From position B to potition C y seconds
  5. Wait y seconds
  6. Call unityevent

Instead of callback in each sequence, you can add an event that calls the function you want to call.

Or you can also do it with code like this if you don't want to add it in the inspector. (I didnt make a clear documentation for it tho):

using UnityEngine;

public class CallbackTest : MonoBehaviour
{
    // Assign the AnimationUI component in the inspector
    [SerializeField] AnimationUI animationUI;

    void Start()
    {
        animationUI.AnimationSequence[2].Event.AddListener(AfterAMoveToB);
        animationUI.AnimationSequence[5].Event.AddListener(AfterAMoveToC);
    }

    void AfterAMoveToB()
    {
        Debug.Log("Callback After A move to B");
    }

    void AfterAMoveToC()
    {
        Debug.Log("Callback After A move to C");
    }
}

Another alternative is to add multiple AnimationUI component. Then look at the Readme.md and use the AddFunctionAtEnd to each animation. Make sure the second one has wait sequence.