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.
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.
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.
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);
}
}
}
}
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 :
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 ?
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().