Hi,
Yes, you can do that. The steps are similar to:
How To: Create Dialogue Database At Runtime
For example, say your script has a data structure like this:
Code: Select all
public class CharacterRoster
{
public List<CharacterData> characters;
}
public class CharacterData
{
public string name;
public string description;
public string knowledge;
public string goals;
}
Assume you've created a static dialogue database in the Dialogue Editor window, and its Base ID is 0.
You can create a runtime database with a Base ID of 10000 to ensure that its internal ID numbers don't conflict with the static database. Some example code:
Code: Select all
// Create database:
var database = ScriptableObject.CreateInstance<DialogueDatabase>();
// Set base ID that's unlikely to conflict with already-loaded databases:
database.baseID = 10000;
// Create a template, which provides helper methods for creating database content:
var template = Template.FromDefault();
// Create actors:
foreach (CharacterData characterData in characterRoster.characters)
{
int actorID = template.GetNextActorID(database);
Actor actor = template.CreateActor(actorID, characterData.name, isPlayer: false);
actor.Description = characterData.description;
actor.fields.Add(new Field("Knowledge", characterData.knowledge);
actor.fields.Add(new Field("Goals", characterData.goals);
}
// Add it to the runtime environment:
DialogueManager.AddDatabase(database);
If you intend to forget this database when leaving the current scene, make sure to remove it from the Dialogue System's runtime environment and destroy it:
Code: Select all
DialogueManager.RemoveDatabase(database);
Destroy(database);