Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Dialogue System for Unity - easy conversations, quests, and more!

Discussion in 'Assets and Asset Store' started by TonyLi, Oct 12, 2013.

  1. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @jrackley - No need for any scripts. Just set up your links like this:

    upload_2019-4-11_21-9-2.png

    If the player chooses "What place?" it will loop back to "Any questions?":

    upload_2019-4-11_21-8-37.png
     
    jrackley likes this.
  2. jrackley

    jrackley

    Joined:
    Jan 26, 2017
    Posts:
    55
    lol, sorry didnt even think about that. Thanks for your time, and repsponse!
     
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Happy to help! :)
     
  4. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    I still have evilas but I didn't put the vmainmenu script.
    My settings in the input device manager is set to keyboard and there are no other assets that uses or controls the cursor
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Something else in your project must be showing the cursor, unless the Input Device Manager's Detect Mouse Control checkbox and Control Cursor State are ticked. (I don't think I got your answer on those checkboxes.)
     
  6. Ekzalphantoss

    Ekzalphantoss

    Joined:
    Sep 27, 2016
    Posts:
    11
    Just letting you know - Typewriter.ogg is broken when the Unity platform is set to WebGL
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @Ekzalphantoss - Thanks. The audio clip is shorter than WebGL allows. It's in the legacy folder, though, so I left it there for other devs who might still be using it. You can always drop in your own typewriter click audio file if you prefer.
     
  8. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    I removed the line and it had no effect but I remember why: I am using Rewired on my UCC character, therefore obviously the preset is not being used as there is no Unity Input component. How can I add that preset state to a UCC character that is using Opsive's "Rewired Input" instead?
     
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Does your character's Opsive Rewired Input component have a Conversing state? When the character's Converse ability starts, it tries to activate this state on whatever input component your character has. It doesn't matter if it's a Unity Input component or a Rewired Input component.
     
    Deckard_89 likes this.
  10. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    It does now! :)
    Solved. Thanks very much for the quick response.
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Glad to help! I'll make sure the manual mentions the Conversing state for Rewired, too.
     
  12. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    @TonyLi Hello, I'm curious whether it's possible to use Dialogue System and the Unity Timeline integration to create the sort of dialogue cutscenes we see in RPGs like Persona 5. Looking at Unity's Timeline, I'm not sure how you'd do something like this, because pausing the timeline will pause any loops that might be on the timeline at the time it's paused, and if you want to use a Continue button then I don't see any other way but to pause the timeline.

    For an example of what I'd be looking for, watch this clip. Notice that the player has enabled the setting that requires them to press a button to advance the dialogue manually. Also notice that the characters continue to idle while the player sits and reads. It's particularly obvious in the interrogation room where Nijima is talking to Joker. From what I'm seeing in Dialogue System and Timeline, this doesn't appear to be possible. Am I missing something?

     
  13. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi @TonyLi I've fixed the mouse cursor problem but I have a problem again. I want the cursor to be active in the start scene but when in the main town scene I want it to be deactivated. I checked the detect mouse control in the dialogue manager in the start scene and unchecked the detect mouse control in the main town scene but still the cursor appears. I think the dialogue manager from the start scene carries over to the main town scene. How can I fix it?
     
  14. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @RecursiveFrog - You can do that in the Dialogue System. I'll attach a small example to this post.

    When you enter the conversation, use the Timeline() sequencer command to pause the timeline:

    Timeline(pause,ExampleTimeline)

    At the end of the conversation, resume it:

    Timeline(resume,ExampleTimeline)

    If you control a character's animation through Timeline, make sure to set Post-Extrapolate to None:

    upload_2019-4-13_13-29-6.png

    This allows the animator to continue playing while the timeline is paused. You can even change up the animation in the conversation using the AnimatorXXX() sequencer commands.

    Hi @dinaloraven234 - That's correct. The Dialogue Manager from the start scene carries over.

    1. On the start scene's Dialogue Manager, tick Detect Mouse Control but untick Control Cursor State.

    2. In the start scene, add a small script like this:
    Code (csharp):
    1. using UnityEngine;
    2. public class SetCursorOnStart : MonoBehaviour {
    3.     public bool showCursor;
    4.     void Start() {
    5.         Cursor.visible = showCursor;
    6.         Cursor.lockState = showCursor ? CursorLockMode.None : CursorLockMode.Locked;
    7.     }
    8. }
    Tick the "Show Cursor" checkbox.

    3. In the gameplay scene(s), add the same script, but untick Show Cursor.

    4. Configure the MenuSystem's PausePanel OnOpen() event to call the Dialogue Manager's InputDeviceManager.ForceCursor with the checkbox ticked. Configure OnClose() to call the same method with the checkbox unticked.
     

    Attached Files:

  15. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Thanks I'll try it :)
     
  16. rolfy01

    rolfy01

    Joined:
    Mar 14, 2016
    Posts:
    10
    Hi, I am interested in using Dialogue system but have a couple of questions before purchase.
    I am pretty far into building my game using Invector melee controller and Adventure Creator integrated.
    1. I see you have integration with both, but being so far in are there any conflicts I should be aware of when integrating DS into my build.
    2. Will Invector stats etc be saved over to Adventure creator save/load automatically using your integration or will it require additional scripting to bridge across.

    Thanks for any info.
     
  17. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @rolfy01,
    No conflicts that I'm aware of.

    Yes. Just add this script to your Invector character along with an Invector Stats Saver:

    Code (csharp):
    1. using PixelCrushers.DialogueSystem;
    2. using UnityEngine;
    3. public class SaversToDialogueSystem : MonoBehaviour
    4. {
    5.     public void OnRecordPersistentData()
    6.     {
    7.         foreach (var saver in GetComponents<PixelCrushers.Saver>())
    8.         {
    9.             DialogueLua.SetVariable(saver.key, saver.RecordData());
    10.         }
    11.     }
    12.     public void OnApplyPersistentData()
    13.     {
    14.         foreach (var saver in GetComponents<PixelCrushers.Saver>())
    15.         {
    16.             if (DialogueLua.DoesVariableExist(saver.key))
    17.             {
    18.                 saver.ApplyData(DialogueLua.GetVariable(saver.key).asString);
    19.             }
    20.         }
    21.     }
    22.     public void OnEnable()
    23.     {
    24.         PersistentDataManager.RegisterPersistentData(this.gameObject);
    25.     }
    26.     public void OnDisable()
    27.     {
    28.         PersistentDataManager.RegisterPersistentData(this.gameObject);
    29.     }
    30. }
     
  18. rolfy01

    rolfy01

    Joined:
    Mar 14, 2016
    Posts:
    10
    Thank you. looks like a certain purchase for me then..
     
  19. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    @TonyLi thanks for the answer. I'm not sure this really solves the problem, though. How would I resume the Timeline when the user clicks the Continue button, or does something that causes the dialogue to continue?

    It sounds like what you're suggesting is that what might be just a single conversation without Timelines, becomes a lot of little conversations and a lot of little Timelines. I really was hoping to avoid that situation, and just use one single timeline and placing Conversation Tracks on the timeline, and still requiring the user to click the Continue button, or use the Rewired controller input to simulate the Continue click.
     
  20. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Sounds good. Feel free to try the evaluation version first if you like. Any content you create with the evaluation version is fully compatible with the paid version.

    Sure, you can do lots of little Timelines, but I agree that you may want to avoid that. Instead, similarly to the example scene that I attached to my reply, you'd use the Timeline() sequencer command to pause and resume a single timeline.
     
  21. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    Unfortunately there are several problems with this approach.
    • If you watch closely in your example. we see the idle loop jump a bit as it has to start over when the Timeline is resumed. We don't want any kind of jumps like this when pausing and resuming a timeline.
    • When I try this in my own scene on Timeline pause, no matter what extrapolation I choose, I cannot get a pose to stay activated, and it simply reverts back to an idle loop on pause, and then snaps back into the pose on resume.
    • A longer timeline seems only to be able to be paused once. Subsequent calls to play simply return it to the beginning.
    • There's not a good way to take advantage of the ability to place specific conversation nodes on the timeline in case we want to make the dialogue window appear at a specific spot in the timeline... without making multiple small conversations, at least.
     
  22. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi @TonyLi how can I destroy a gameobject when going to a scene? I have a cutscene in the main town scene and it plays at the start. And when I go to the tavern scene then goes back to the main town scene the cutscene triggers again. What I want is the cutscene to play at the very first then when going back and forth in the main town scene it will not play anymore. BTW I'm using cinema director for the cut scene and I know you have an integration with it
     
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    I'll look into this further. It looks like Timeline resets the Animator when it pauses. I don't know that there will be a solution other than not allowing Timeline to control that character's Animator, or immediately use AnimatorPlay() in the conversation to put the Animator in the desired state -- although this will cause a jump. You could change the camera angle temporarily to mask the jump. This may just be a limitation of Timeline when it comes to interaction that depends on player input.

    Add nostop to the Timeline() command. It avoids timing issues with pausing and resuming. I updated the example scene in my previous reply.

    Timeline(resume,ExampleTimeline,nostop)

    What if the Start Conversation clip had an option to jump to a specific conversation node?

    1. Add a Dialogue System variable to remember whether you've played the cutscene. For example, call it "PlayedIntroCutscene".
    2. Set the cutscene inactive, or configure it to not autostart.
    3. Configure a Dialogue System Trigger that runs OnStart. In the Condition section, require that PlayedIntroCutscene is false. Add two actions:
      • Run Lua Code: Set PlayedIntroCutscene to true.
      • OnExecute() Event: Activate the cutscene (if it autostarts), or play it.
     
  24. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi @TonyLi I tried your tip above using the setcursoronstart it works on the start scene and main town scene but when I hit the pause button(p) the cursor won't appear
     
  25. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi in the on execute unity event will I set the cut scene gameobject inactive? So it can start? My cut scene trigger is on start using the cinemadirector. I disable the cut scene and set the conditions you said and in my execute unity event I enabled the cut scene gameobject but it won't play
     
  26. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    I also think this is a limitation of Timeline, and possibly a Timeline dealbreaker if there's a different way to do things. Camera angle changes on every continue feels really excessive.

    That does work to keep the timeline from traveling to strange places.


    That isn't quite what I was talking about, but it's close. It's not that I'm looking to make skippable cutscenes, but more that I'd want to be able to place specific dialogue nodes from a given conversation at different timestamps. To do that currently we only really have a Start Conversation Clip, but if we're already in a conversation should we really use another Start Conversation Clip to start from a different node, that we know only by its number and not by any kind of dropdown?

    The only other option I see is that every alternating dialogue node needs to have an empty node in it that does nothing besides call Timeline(resume,MyTimeline,nostop); And each dialogue node then immediately starts with Timeline(pause,MyTimeline,nostop); Then place Continue Conversation Clips on the timeline where we think we should continue to the next dialogue node and pause the Timeline... but then we have to jump back and forth between the dialogue editor and the timeline editor without having any good way to tell where on the timeline our specific dialogue nodes are.
     
    Last edited: Apr 14, 2019
  27. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    @TonyLi In regards to : "I'll look into this further. It looks like Timeline resets the Animator when it pauses."

    I notice that there is integration for other cutscene composition tools such as Slate. Do you know offhand if these tools suffer the same issue? Might they allow me to create the cutscenes I'm thinking of with minimal hassle?
     
  28. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @dinaloraven234 - I'll put together a set of example scenes and send it to you later today. I think that will explain it better.

    I'll experiment with ways to save the animator's state right before pausing and restore that state right after pausing. The Dialogue System has an AnimatorSaver component that does something similar, so I already have most of the code. If I can't get it to work with Timeline, it may just be a dealbreaker. I confirmed that Unity's own Timeline example has the same issue. It does non-interactive dialogue that pauses for the player to press space to continue each line, but it also resets the animator whenever it pauses to wait for space.

    I'll test SLATE today and let you know. The developer is very responsive. If nothing else, he may be able to implement something faster than Unity could move on it.
     
  29. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Thanks @TonyLi
     
  30. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
     
  31. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    Sounds good. I tried the SLATE integration last night and I noticed that your documentation indicates that we should be able to pause and resume a Slate Cutscene, but it's not actually implemented in the SequencerCommandSLATE integration. Adding it myself was easy enough, but still thought you should have a heads up that it was missing from your implementation.
     
  32. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Pause & resume were added in version 2.1.5, which is being released today. I jumped the gun and updated the online manual last night, hence the discrepancy.
     
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    @dinaloraven234 - Here's a set of example scenes. You might want to import them into a new project. Also import Invector, Cinemachine, Dialogue System, and the Dialogue System's Invector support packages from Common and Dialogue System. Add the scenes to the build settings as scenes 0 - 5. Then play scene 0. The intro cutscene in gameplay scene A just moves the camera around. If you go to gameplay scene B and then return to A, you'll notice that the intro cutscene doesn't play again. Remember that Invector maps the "Cancel" input to backspace; if you're using the defaults, press backspace to open and close the menu. If you have any questions, just let me know.
     

    Attached Files:

  34. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    @RecursiveFrog - An issue with Timeline is that it can play animation clips that are not in the character's animator controller. This means we can't save the state of the animator just before pausing and then restore that state just after the pause resets the animator. A poor substitute, but maybe something that could be workable, is to not use animation tracks just in these situations. Instead, you could write a custom playable to control the animator -- sort of like how I used Play Sequence in the attached example.

    I've reached out to the SLATE dev to see if he has any ideas. I'll keep you updated.
     

    Attached Files:

  35. rolfy01

    rolfy01

    Joined:
    Mar 14, 2016
    Posts:
    10
    Hi, been trying out the Invector integration with your demo and works great with everything including health stats etc, the save/load inventory gets pretty messed up though. particularly when USE_INVECTOR_INVENTORY is defined in player settings. With the equipment display window emptying and weapons such as shield being duplicated into the right hand equip sword slot etc.
    Pretty sure I set it all up as instructed but may still be missing something obvious :)

    I see you seem to consider this still a work in progress "This saver is a work in progress. It saves and restores the character's inventory but doesn't yet restore items to their original equip areas" I am just wondering if the error is on my end and should I look into it all further or should I wait for an update?
    Checking further the equip errors I see seem to be a lot worse in the most recent Invector release v2.4.0 which is understandable since they change things often and makes it difficult to keep up on. :)
     
    Last edited: Apr 15, 2019
  36. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi @TonyLi thanks for this but can you use cinema director instead of cinemachine because its not compatible with my unity 5.6.6 I'm using a 32 bit os and got errors when importing cinemachine because of its only compatible with unity 2017 and up. I'll send you a copy of cinema director if you don't have any
     
  37. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    That's a neat sample and probably useful for most situations like these, I think. What would be really useful is if the Start Conversation Clip were capable of inspecting the contents of the selected conversation and offer a dropdown list of the conversation options available instead of us having to look back at the int ID of the node we want to start the conversation from and enter that into an int field. The current system feels a little precarious since we have to work with raw ints.

    In working with SLATE I have found it's both more featured than Timeline but also possibly more buggy, as working with it in 2018.3.12f1 is an exercise in frustration due to unexpected results in the editor. It might still end up being the better choice if it can ultimately allow these kinds of cutscenes to be made, but if it cannot then your example here really appears to meet the desired output even if the input isn't 100% polished.
     
  38. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @rolfy01 - Things should have been working correctly through version 1.3.0. Which Invector asset are you using, and what version? I'll check it out. I'll probably need to post an update on the Dialogue System Extras page because Dialogue System 2.1.5 just released today. (It doesn't include any updated Invector package beyond 2.1.4 though.)

    The example uses Cinema Director, but I built it in 2018.1. I'll rebuild it in 5.6.6 later today.

    That's a good idea. It will still use raw ints under the hood, but I'll change the inspector to use a dropdown that shows the dialogue text. I'll try to get that implemented this week.

    I like SLATE, too. If you've encountered a bug, try contacting the dev on the SLATE forums. He's usually very responsive.
     
  39. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Thanks I'll wait for it
     
  40. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Dialogue System 2.1.5 Released

    Version 2.1.5 is now available on the Asset Store. This update includes minor bug fixes and a few small additions, such as the SetDialoguePanel() sequencer command to temporarily hide the dialogue panel during parts of conversations.

    Version 2.1.5 Release Notes:
    Core:
    • Changed: OnConversationLineCancelled now passes PC line, not previous NPC line, if PC line is what was cancelled.
    • Added: Sequencer command SetDialoguePanel(true|false).
    • Added: Only For PC continue button option.
    • Improved: StandardUIQuestTracker inspector now has Clear PlayerPrefs Visibility Toggle button.
    • Improved: Added Use PlayOneShot option to typewriter effects.
    • Fixed: Chat Mapper XML export format incorrectly exported Dialogue Text field as Localization type instead of Text type.
    • Fixed: UIPanel NullReferenceException if scene didn’t have an EventSystem.
    • Fixed: Fade() sequencer command sets alpha to fully 1 or 0 at end to avoid floating point rounding errors.
    • Fixed: ProximitySelector gracefully handles usables in range that have been destroyed or deactivated when choosing a new usable.
    • Fixed: Rare error message with some complex sequences.
    • Fixed: Lasso selection auto arrange no longer also arranges unconnected red nodes unless they're part of selection.
    Third Party Support:
    • articy:draft: Can now choose to name elements by technical name; jumps that link only to other jumps or hubs are now converted as group nodes; more gracefully handles XML file inconsistencies.
    • i2 Localization: Added option to append actor name or dialogue text to dialogue entry terms.
    • Opsive Controllers: Converse ability can now use different states based on whether player is using mouse or not.
    • PlayMaker: Added Sync GameObject. Updated actions for .NET4.
    • SLATE: Added pause and resume parameters.
    • uSurvival: Updated for version 1.43.
     
    DMRhodes and Deckard_89 like this.
  41. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi @TonyLi have you imported it to 5.6.6? I just really need it as my deadline for the project is near
     
  42. rolfy01

    rolfy01

    Joined:
    Mar 14, 2016
    Posts:
    10
    Hi, I tested the demo with a new project and clean install of Invector melee v2.4.0. I believe v2.3.0 was a core update which had major changes in some structural classes to receive the new AI and namespace on every vScript, so not surprising it got glitched.
    Your stats saver still works perfectly though :)
     
    Last edited: Apr 15, 2019
  43. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    Any new UI's for the Dialogues and Save System?
     
  44. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Scenes aren't backwards-compatible with older versions, so I had to rebuild the whole thing from scratch. Here's a version for Unity 5.6.6.

    Thanks for the version info. I'll check it out and reply back here with an answer.

    No, but the Asset Store has a huge number of UI skins. It's pretty easy to get one and apply it to the Dialogue System's dialogue UI elements. You can make some pretty sharp-looking UIs just by getting a UI skin from the store and dropping the textures on whichever template you prefer.
     

    Attached Files:

  45. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    Hi @TonyLi the cut scene now works properly and its thanks to you. I have one last problem on my hand, how can the menu system not carry over to other scene. I have to disable the vinventory script in the main town scene and but in the start scene i didn't disable and enable it in the menu settings and what happens is that the menu settings in the start scene replaces the menu settings in the main town scene and overrides the settings that I adjusted in the main town scene
     
  46. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Inspect the MenuSystem in each scene. On the Title Menu component, untick Act As Singleton. This will, however, cause it to become unlinked from the Dialogue Manager's Input Device Manager component. You can try moving the Input Device Manager to the Menu System and hooking up the PausePanel's OnOpen() and OnClose() events again to show/hide the cursor. In this case, remember to untick the Input Device Manager's Singleton checkbox, too.
     
  47. dinaloraven234

    dinaloraven234

    Joined:
    Dec 20, 2018
    Posts:
    141
    So I'll attach the input device manager in the menu system and remove it from dialogue manager? Is that correct? Thanks for the quick response I'll test it now
     
  48. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Yes, that's correct. Make a backup beforehand in case you run into any issues. Also untick the Input Device Manager's Singleton checkbox. And after you move the Input Device Manager, update the PausePanel's OnOpen() and OnClose() events to call its ForceCursor method to show/hide the cursor when the pause menu is open/closed.
     
  49. Ekzalphantoss

    Ekzalphantoss

    Joined:
    Sep 27, 2016
    Posts:
    11
    @TonyLi Hi again. You had suggested I use OnConversationEnd and OnConversationLine for events. Although they do work with my current implementation I was wondering if there was a more elegant solution available that I'm not aware of. Here's my current code for sending choice events from the dialog to the place they are processed:
    Code (CSharp):
    1.     public void OnConversationLine(Subtitle subtitle)
    2.     {
    3.         //if line starts with the format "1.", send it as a choice event
    4.         var k = subtitle.formattedText.text;
    5.         if (!string.IsNullOrEmpty(k) && k.Length > 1)
    6.         {
    7.             if (k[1] != '.')
    8.             {
    9.                 return;
    10.             }
    11.  
    12.             var firstChar = k[0].ToString();
    13.  
    14.             int result;
    15.             bool success = int.TryParse(firstChar, out result);
    16.             if (success)
    17.             {
    18.                 _choiceSubject.OnNext(result - 1);
    19.             }
    20.         }
    21.     }
    Since choices turn into conversation lines after they are chosen only the choice triggers the event. And if the line begins with for example "1." I activate my own trigger with "0" as the chosen option.
    The problem is that this requires whoever is writing the dialogue to always type 1.,2.,3. for the choices and must be sure that they are in the same order as in the dialogue system. Moreover, if someone ever decides to start a normal line with "1." it might cause errors.

    So my questions are: is there some ready-made event to differentiate between choices and is there a default way to differentiate between normal lines and choices?
     
  50. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @Ekzalphantoss - Check subtitle.speakerInfo.IsPlayer. If it's true, then the player is speaking the line.

    If the player can speak lines that aren't shown first in a response menu, you can flip a bool in OnConversationResponseMenu:

    Code (csharp):
    1. bool showedResponseMenu = false;
    2.  
    3. void OnConversationEnd(Transform actor)
    4. {
    5.     showedResponseMenu = false;
    6. }
    7.  
    8. void OnConversationResponseMenu(Response[] responses)
    9. {
    10.     showedResponseMenu = true;
    11. }
    12.  
    13. void OnConversationLine(Subtitle subtitle)
    14. {
    15.     if (subtitle.speakerInfo.isPlayer && showedResponseMenu)
    16.     {
    17.         Debug.Log("This was a choice: " + subtitle.formattedText.text);
    18.     }
    19.     showedResponseMenu = false;
    20. }