Page 1 of 1
Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 7:02 am
by Abelius
Hi there,
Since its implementation, I've been using shortcuts extensively. Would be weird otherwise, being the guy that asked for them.
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!
Re: Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 9:14 am
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)".
Re: Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 9:39 am
by Abelius
Thanks Tony,
Just one doubt I have... Can I include line break code \n\r inside the sequencer shortcut value?
Re: Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 9:47 am
by Tony Li
Yes, that's fine, and you can shorten it to "\n" if you prefer. The "\r" isn't required.
Re: Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 10:07 am
by Abelius
Thank you.
Oh, and another question... lol, I'm remembering them as I go. I suck.
Which one runs first? Sequencer Shortcut components? Custom scripts? Only the RNG gods know?
Re: Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 10:40 am
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.)
Re: Shortcuts registration via C# script ?
Posted: Tue Oct 16, 2018 10:44 am
by Abelius
Thank you Tony.
That's all I need...
...for now. <insert Dr. Evil cackle here>