Hi Leonard,
Please try the script below. After adding it to a scene, you can specify a local filename and a URL. If you set loadLocalFile true, it will load the local XML file. If you set it false, it will load from WWW. By default, I pointed the WWW version to a test file because I didn't want to expose your original XML file, but you can change it to your XML file. The script simply loads the XML and prints all the conversation titles to the Console.
You'll notice that it points to articy_test
2.xml. This is a version of articy_test.xml which I've saved in UTF-8
without BOM format. The .NET library can't parse XML files that have been saved in UTF-8
with BOM format. If the file has BOM, it will raise the error you reported. (If you want to see the error, change the WWW filename to articy_test.xml without the 2 at the end. WWW preserves BOM, although reading the file locally seems to work fine either way.) The solution is to save your XML file in "UTF-8 without BOM" format. I use Notepad++. To do this, I went to the Encoding menu and changed it from "Encode in UTF-8-BOM" to "Encode in UTF-8".
LoadArticyRuntime.cs
Code: Select all
using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
using PixelCrushers.DialogueSystem.Articy;
public class LoadArticyRuntime : MonoBehaviour
{
public bool loadLocalFile = true;
public string localFilename = @"C:\Users\Leonard\Desktop\articy\cs_latest.xml";
public string fileUrl = @"http://pixelcrushers.com/dialogue_system/download/fileshare/articy_test2.xml";
IEnumerator Start()
{
ConverterPrefs myPrefs = new ConverterPrefs
{
EncodingType = EncodingType.UTF8,
StageDirectionsAreSequences = false,
ConvertDropdownsAs = ConverterPrefs.ConvertDropdownsModes.Ints,
ConvertSlotsAs = ConverterPrefs.ConvertSlotsModes.ID,
RecursionMode = ConverterPrefs.RecursionModes.On,
FlowFragmentMode = ConverterPrefs.FlowFragmentModes.Quests,
DirectConversationLinksToEntry1 = false,
Overwrite = true
};
DialogueDatabase database = null;
if (loadLocalFile)
{
// Load local file:
var xml = System.IO.File.ReadAllText(localFilename);
Debug.Log(xml);
database = ArticyConverter.ConvertXmlDataToDatabase(xml, myPrefs);
}
else
{
// Load from WWW:
if (Application.internetReachability == NetworkReachability.NotReachable) yield return null;
using (WWW www = new WWW(fileUrl))
{
Debug.Log("XML file Downloading");
yield return www;
if (www.isDone)
{
Debug.Log("Download Success");
Debug.Log(www.text);
database = ArticyConverter.ConvertXmlDataToDatabase(www.text, myPrefs);
}
}
}
if (database == null)
{
Debug.Log("Database is null!");
}
else
{
Debug.Log("Conversations in database:");
foreach (var conversation in database.conversations)
{
Debug.Log(conversation.Title);
}
}
}
}