Re: messaging-app-like UI
Posted: Sat Feb 09, 2019 10:27 am
Here's a tested example script with error checking. Press F1 to log the last line of the conversation.
To use this script in the start scene after returning from the gameplay scene, make sure you're using a recent version of the Menu Framework. Older versions of the Menu Framework reset the database when returning to the start scene. If the database is reset, it won't contain the DialogueEntryRecords_* values yet.
To use it when first starting the game (before you've gone to the gameplay scene), tick the Menu System > Auto Save Load component's Load On Start checkbox. This will load the database when game starts.
PrintLastEntry.cs
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class PrintLastEntry : MonoBehaviour
{
[ConversationPopup]
public string conversation;
void Update()
{
if (Input.GetKeyDown(KeyCode.F1))
{
// Get the last entry for conversation:
string history = DialogueLua.GetVariable("DialogueEntryRecords_" + conversation).asString;
string[] fields = history.Split(';');
var numRecords = (fields.Length > 0) ? Tools.StringToInt(fields[0]) : 0;
Debug.Log("Conversation has " + fields[0] + " records.");
if (numRecords > 0)
{
int conversationID = Tools.StringToInt(fields[fields.Length - 3]);
int entryID = Tools.StringToInt(fields[fields.Length - 2]);
Debug.Log("Last record is [" + conversationID + ":" + entryID + "] -- " + history);
DialogueEntry entry = DialogueManager.masterDatabase.GetDialogueEntry(conversationID, entryID);
if (entry != null)
{
Debug.Log("Last entry is: " + entry.DialogueText);
}
}
}
}
}
To use it when first starting the game (before you've gone to the gameplay scene), tick the Menu System > Auto Save Load component's Load On Start checkbox. This will load the database when game starts.