Custom sequence Stop()

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Custom sequence Stop()

Post 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?
User avatar
Tony Li
Posts: 21987
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom sequence Stop()

Post 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.
thecodehermit
Posts: 41
Joined: Mon Jul 19, 2021 11:27 am

Re: Custom sequence Stop()

Post by thecodehermit »

That did it perfectly. I never would have thought that was the way to do it. Thanks again !
User avatar
Tony Li
Posts: 21987
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom sequence Stop()

Post by Tony Li »

Glad I could help!
Post Reply