Hi,
You first need a reference to the
DialogueDatabase that contains the conversation. The code below adds a public variable for a DialogueDatabase:
Code: Select all
public class ValidateConversationNodes : MonoBehaviour {
public DialogueDatabase database; //<--ADD THIS.
public string ConversationTranscript = "abc.txt";
...etc...
Working with the database is quite easy. In brief:
Here's some basic code:
Code: Select all
private void PerformConversationValidation() {
// Make sure we have a reference to a database:
if (database == null) database = EditorTools.FindInitialDatabase();
if (database == null) {
Debug.LogError("No dialogue database!");
return;
}
// Find conversation by name:
var conversation = database.GetConversation(ConversationName);
if (conversation == null) {
Debug.LogError("Conversation " + ConversationName + " not found in database!");
return;
}
// For each node in conversation:
// - Retrieve the nodes' sequence and dialogue text
// - Confirm the node calls the correct audio file (check sequence)
foreach (var dialogueEntry in conversation.dialogueEntries) {
var dialogueText = dialogueEntry.DialogueText;
var sequence = dialogueEntry.Sequence;
// If you modify the sequence:
dialogueEntry.Sequence = your_modified_sequence;
}
ValidateConversation = false;
Debug.Log("Successfully validated\n");
}
A few notes:
1. The
DialogueEntry class has helper properties for DefaultText, Sequence, and other common fields. If you're using language localization, please be aware that many of these properties return the localized field for the current language. If you want the default dialogue text (not the localized version), use the DefaultDialogueText property instead. (See the docs for more info.)
2. If you've already written your content, it might not be worthwhile to look into entrytags. However, they can make this kind work easier. Here are the docs:
How to Use entrytags.
3. The code above calls EditorTools.FindInitialDatabase(), which is a Dialogue System editor class. I'm assuming that your code will be marked editor only so it won't be included in builds, since EditorTools won't compile in builds. If you want to run it in builds, you can remove that line.