Shortcuts registration via C# script ?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Shortcuts registration via C# script ?

Post by Abelius »

Hi there,

Since its implementation, I've been using shortcuts extensively. Would be weird otherwise, being the guy that asked for them. :lol:

And as I'm no real coder, I've been adding them using several Sequencer Shortcuts components in the Dialogue Manager. Now, I have so many of them that managing the list is becoming more and more of a hassle.

I'd like to move all of them to an attached C# script, but I can't find relevant info on how exactly I should do it. Could you help me with that, please?

Thanks!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Shortcuts registration via C# script ?

Post by Tony Li »

Hi,

Use Sequencer.RegisterShortcut() and Sequencer.UnregisterShortcut().

Code: Select all

using PixelCrushers.DialogueSystem;
...
Sequencer.RegisterShortcut("talk", "AnimatorPlayWait(MoveMouth)");
...
Sequencer.UnregisterShortcut("talk");

In version 1.8.6+, shortcuts stack. So if you were to use this code:

Code: Select all

Sequencer.RegisterShortcut("talk", "AnimatorPlayWait(MoveMouth)");
Sequencer.RegisterShortcut("talk", "AudioWait(entrytag)");
Then "talk" would be mapped to "AudioWait(entrytag)" because it's on the top of the stack.

If you then use this code:

Code: Select all

Sequencer.UnregisterShortcut("talk");
Then "talk" would be mapped to "AnimatorPlayWait(MoveMouth)", which is next on the stack after removing "AudioWait(entrytag)".
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Shortcuts registration via C# script ?

Post by Abelius »

Thanks Tony,

Just one doubt I have... Can I include line break code \n\r inside the sequencer shortcut value?
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Shortcuts registration via C# script ?

Post by Tony Li »

Yes, that's fine, and you can shorten it to "\n" if you prefer. The "\r" isn't required.
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Shortcuts registration via C# script ?

Post by Abelius »

Thank you.

Oh, and another question... lol, I'm remembering them as I go. I suck. :lol:

Which one runs first? Sequencer Shortcut components? Custom scripts? Only the RNG gods know? :P
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Shortcuts registration via C# script ?

Post by Tony Li »

The Sequencer Shortcuts component registers shortcuts in the OnEnable phase.

If your script registers shortcuts in Awake, it's guaranteed to register them before Sequencer Shortcuts.

If you scroll down halfway on Unity's Execution Order of Event Functions page, a handy flowchart explains when each phase runs.

If your script registers in OnEnable or Start, only the RNG gods know. (That's not entirely true. You can manually set Script Execution Order, but it might be more hassle than it's worth.)
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Shortcuts registration via C# script ?

Post by Abelius »

Thank you Tony.

That's all I need...

...for now. <insert Dr. Evil cackle here> :P
Unity 2019.4.9f1
Dialogue System 2.2.15
Post Reply