Tips / Best practices for customizing Selector behvior

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
NashFM
Posts: 8
Joined: Mon Dec 15, 2014 12:41 am

Tips / Best practices for customizing Selector behvior

Post by NashFM »

I am making a 2D top-down game similar to an SNES RPG like Chrono Trigger or Secret of Mana. Before purchasing DS, I had written my own "select/use" code using an abstract "Interactable" class, and an Interaction component on my player that uses raycasts to check in front of the player for Interactable objects, to achieve that old RPG style of walking up to NPCs and objects. I purchased DS for the dialog writing / database / etc, and didn't even know about the Selector features until recently.



I was wondering if you could advise on how to best integrate DS into my game. I don't mind rewriting or even tossing my stuff. Some things that come to mind (but I'm open to anything you'd advise): Should I just hand-send "OnUse" messages from my own scripts? Are there similar Selector messages I should just hand-send, for mouse-over and whatnot? Or is there a Selector base class I could / should subclass to make my own?



Another aspect of this is having a Selector (or whatever I end up using) perform some action before actually sending the OnUse message, or having a Trigger wait to complete an action before starting the conversation. Ideally, I'd like to (maybe in a coroutine?) be able to pathfind to the Usable/Interactable object and THEN start the dialog. The reason is I am supporting both controller movement (JRPG style, as stated above) and mouse/click movement for PC/Tablet - so I'll need Selecting to be based on both my own raycast code (or similar) and mouse selection.



Note that a proximity sensor doesn't help since I need to also consider which way my character is facing, and since it is a 2D game, I am swapping sprites rather than rotating my game object - so I think I do have to do this by hand with the raycasts.



Thanks again for the help! =)
User avatar
Tony Li
Posts: 20883
Joined: Thu Jul 18, 2013 1:27 pm

Tips / Best practices for customizing Selector behvior

Post by Tony Li »

If your own interactable/interaction classes work the way you want, it's probably easiest to use them and hand-send OnUse. The Dialogue System's triggers accept three forms of OnUse: OnUse(transform), OnUse(string), and OnUse(). When possible, use OnUse(transform) so you can pass the transform of the character (e.g., player) that's using the trigger. So in your Interaction class, add something like:

target.SendMessage("OnUse", this.transform);

The triggers and ProximitySelector implement OnTriggerEnter() and OnTriggerEnter2D(), so you can use them in 2D scenes. But, as you said, they don't do quite what you're looking for. I left Selector and ProximitySelector out of the precompiled DLL to keep them accessible as customizable starting points for people who don't already have an interaction system in place. (The source files for the DLLs are in Scripts/SourceCode.unitypackage.) Selector and ProximitySelector aren't core Dialogue System classes. Rip code from them if it's helpful, but don't certainly feel obligated to use them.



As far as messages and event hooks go, here's the documentation on Script Messages and the API reference for DialogueManager, which has methods for starting conversations, playing sequences, displaying gameplay alerts, etc.
NashFM
Posts: 8
Joined: Mon Dec 15, 2014 12:41 am

Tips / Best practices for customizing Selector behvior

Post by NashFM »

Awesome, this is all exactly what I was looking for! Thanks, Tony! You rock.
Post Reply