Page 1 of 1

Custom sequence Stop()

Posted: Wed Jul 28, 2021 9:45 am
by thecodehermit
Hello again. I am making a bunch of custom sequencer commands and got in a bit of an issue with one function.

I have a camera zoom function in an external file. I created a custom sequencer file and will call the zoom function from there. However I am not sure how to call the Stop() function after the zoom has finished.

I want to somehow call the Stop() function from the external file, after the zoom has finished. Though I am not quite sure how to achieve that... Do I somehow access the sequencer file and then call Stop() when the zoom finishes, or do I make a event or message inside the sequencer file so it waits for the zoom to finish?

Re: Custom sequence Stop()

Posted: Wed Jul 28, 2021 12:46 pm
by Tony Li
Hi,

It would be best to use an event, message, or callback. For example:

Code: Select all

public class SequencerCommandZoom : SequencerCommand
{
    void Awake()
    {
        ExternalZoomScript.instance.Zoom(Stop);
    }
}
and:

Code: Select all

public class ExternalZoomScript : MonoBehaviour
{
    ...
    public void Zoom(System.Action callbackWhenDone)
    {
        StartCoroutine(ZoomCoroutine(callbackWhenDone));
    }
    
    IEnumerator ZoomCoroutine(System.Action callbackWhenDone)
    {
        //... your code here to zoom ...
        // When done, call the callback:
        callbackWhenDone();
    }
}
I glided over some other code that your ExternalZoomScript will certainly need, but hopefully that gets the idea across. If not, let me know if you have any questions.

Re: Custom sequence Stop()

Posted: Wed Jul 28, 2021 3:58 pm
by thecodehermit
That did it perfectly. I never would have thought that was the way to do it. Thanks again !

Re: Custom sequence Stop()

Posted: Wed Jul 28, 2021 4:21 pm
by Tony Li
Glad I could help!