Page 1 of 1
Convert Chat Mapper XML to Database in C#
Posted: Fri Jul 10, 2015 6:03 am
by Rewar
Hello !
I must make an automatic converter which could read a ChatMapper XML file in a specified folder and convert it into a DialogueDatabase. After that, I must launch the generated dialogue in the scene. But I still don't know how to make it. I've tried to attach the DialogueDatabase to the Gameobject Dialogue Manager. It does'nt work.
This is code that I made.
Code: Select all
ChatMapperProject cmpp = ChatMapperTools.Load(@"Assets/Resources/Dialogs/source/scenar3.xml");
DialogueDatabase ddb = cmpp.ToDialogueDatabase();
DialogueSystemController dsc = GameObject.Find( "Dialogue Manager" ).GetComponent<DialogueSystemController>();
dsc.initialDatabase = ddb;
If you have a solution, it would be great to hear it. Thank you.
Re: Convert Chat Mapper XML to Database in C#
Posted: Fri Jul 10, 2015 8:36 am
by Tony Li
Hello,
DialogueManager.initialDatabase is only used when the Dialogue Manager starts. To add a database later, use
DialogueManager.AddDatabase():
Code: Select all
ChatMapperProject cmpp = ChatMapperTools.Load(@"Assets/Resources/Dialogs/source/scenar3.xml");
DialogueDatabase ddb = cmpp.ToDialogueDatabase();
DialogueManager.AddDatabase(ddb);
Re: Convert Chat Mapper XML to Database in C#
Posted: Thu Jul 16, 2015 4:12 am
by Rewar
Thank you for that tip but how could I load the Dialogue in my scene on Start ? I've a DialogueManager gameobject and un ConversationTrigger but evenif I change their DialogueDatabase, it still not work.
Re: Convert Chat Mapper XML to Database in C#
Posted: Thu Jul 16, 2015 9:17 am
by Tony Li
Hi,
If you're specifying the XML file at design time, it's easier to treat it as a TextAsset. This way you don't have to find the user's current path at runtime.
Try adding a script like this:
Code: Select all
using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
public class AddConvertedDatabase : MonoBehaviour {
public TextAsset xmlFile; //<-- Assign your XML file here in the inspector.
public IEnumerator Start() {
yield return null; // Allow 1 frame for Dialogue Manager to initialize.
ChatMapperProject cmpp = ChatMapperTools.Load(xmlFile);
if (cmpp == null) {
Debug.LogError("Can't load XML file.");
} else {
DialogueDatabase ddb = cmpp.ToDialogueDatabase();
if (ddb == null) {
Debug.LogError("Can't convert Chat Mapper project to dialogue database.");
} else {
DialogueManager.AddDatabase(ddb);
}
}
}
}
Re: Convert Chat Mapper XML to Database in C#
Posted: Thu Jul 16, 2015 9:49 am
by Rewar
Maybe I express my idea badly. That XML file to import into my scene at the Start of the game is in a specified repository, so I don't have any problem to load it in C#.
Actually, I start the game by press Play, I loaded the file and added it to DialogueDatabase like this :
Code: Select all
ChatMapperProject cmpp = ChatMapperTools.Load(@"Assets/Resources/Dialogs/source/scenar3.xml");
DialogueDatabase ddb = cmpp.ToDialogueDatabase();
DialogueManager.AddDatabase( ddb );
But after that, I want to launch the added Dialogue. I've already a DialogueManager gameobject in my scene and a Character which have a component ConversationTrigger. How can I start the conversation in the loaded Database ?
Re: Convert Chat Mapper XML to Database in C#
Posted: Thu Jul 16, 2015 10:54 am
by Tony Li
DialogueManager.AddDatabase(ddb) merges the ddb database into the Dialogue Manager's master runtime database. All conversations in scenar3.xml will be available in the master database.
Here are two different methods to start the conversation:
Method #1:
On the Conversation Trigger, click the toggle next to the conversation title. This will switch between a dropdown menu and a text field. Since the dialogue database doesn't exist at design time, you can't use the dropdown menu. Instead, enter the conversation title in the text field.
Method #2:
Don't use Conversation Trigger. Call DialogueManager.StartConversation().
Code: Select all
ChatMapperProject cmpp = ChatMapperTools.Load(@"Assets/Resources/Dialogs/source/scenar3.xml");
DialogueDatabase ddb = cmpp.ToDialogueDatabase();
DialogueManager.AddDatabase( ddb );
// Add this:
DialogueManager.StartConversation("My Conversation Title", actorTransform, conversantTransform);
Re: Convert Chat Mapper XML to Database in C#
Posted: Thu Jul 16, 2015 11:20 am
by Rewar
Thank you it works. That's the second method, because I can't touch the Unity Editor, so I must code all changements in C#.
That's ok now, thank you
Re: Convert Chat Mapper XML to Database in C#
Posted: Thu Jul 16, 2015 11:36 am
by Tony Li
Happy to help! I'm glad it's working now.