How to use @Message sequence with script based conversation?
Posted: Wed Aug 17, 2022 10:00 pm
Hello,
I'm trying to create VN dialogues with "Dialogue system for Unity", "Dialogue system Extras".
Although I create C# and json based dialogue system referenced topic "Executing from script"
https://www.pixelcrushers.com/phpbb/vie ... 83f3af455f
But, there are not working Message sequence system like as @Message.
Can you tell me what I'm missing?
-- below is main part of my c# and json script --
[My C# code]
// A is start class
// preloaded Singleton
[My Json (Prologue_Main_Start.json)]
The subject is load next json(Start01.json) and continue to next conversation.
case 1: completable
Generated Sequence:
AddScenario(Prologue_Main_Start,Start01);
EndScenario();
This is possible, but there are restrictions like can not delay ...
case 2: not completable
Generated Sequence:
AddScenario(Prologue_Main_Start,Start01)->Message(Done1);EndScenario()@Message(Done1);
"@Message" can not receive ...
Best Regards.
IAF
I'm trying to create VN dialogues with "Dialogue system for Unity", "Dialogue system Extras".
Although I create C# and json based dialogue system referenced topic "Executing from script"
https://www.pixelcrushers.com/phpbb/vie ... 83f3af455f
But, there are not working Message sequence system like as @Message.
Can you tell me what I'm missing?
-- below is main part of my c# and json script --
[My C# code]
// A is start class
Code: Select all
public class A
{
private void Start(){
GameManager.Instance.ScenarioList.Add("Prologue_Main_Start");
PlayScenario().Forget();
}
}
Code: Select all
public class GameManager : SingletonMonoBehaviour<GameManager>
{
// ----- Variables for scenario -----
// Increment when start conversation
private int conversationID = 0;
// Read file name List
public List<string> ScenarioList = new List<string>();
// Now loading file name
public string nowLoadingScenario;
// if during conversation, true, if not, false
public bool scenarioProgressing;
// ----- -----
public ResourceStore globalResource = new ResourceStore();
public ResourceStore sceneResource = new ResourceStore();
void Start()
{
DontDestroyOnLoad(this);
}
public void SetScenarioLabel(string addressableLabel)
{
nowLoadingScenario = addressableLabel;
}
public async UniTask StartConversation()
{
conversationID++;
// Flag set
GameManager.Instance.scenarioProgressing = true;
// Create database:
var database = ScriptableObject.CreateInstance<DialogueDatabase>();
// Create a template, which provides helper methods for creating database content:
var template = Template.FromDefault();
// Our actors defined in dialogue database:
int aldoID = 1;
int richardID = 2;
int lucyID = 3;
// Create a conversation: [ID 0=START]
var conversationTitle = nowLoadingScenario;
var conversation = template.CreateConversation(conversationID, conversationTitle);
conversation.ActorID = aldoID;
conversation.ConversantID = richardID;
database.conversations.Add(conversation);
// START node: (Every conversation starts with a START node with ID 0)
int entryID = 0;
var node = template.CreateDialogueEntry(entryID++, conversation.id, "START");
node.Sequence = "None()"; // START node usually shouldn't play a sequence.
conversation.dialogueEntries.Add(node);
// Node 1: Only execute Continue(). if without this, then fault occured.
var previousNode = node;
node = template.CreateDialogueEntry(entryID++, conversation.id, string.Empty);
node.Sequence = "Continue();";
conversation.dialogueEntries.Add(node);
// Link from START:
var link = new Link(conversation.id, previousNode.id, conversation.id, node.id);
previousNode.outgoingLinks.Add(link);
// Add it to the runtime environment and play it:
DialogueManager.AddDatabase(database);
DialogueManager.StartConversation(conversationTitle);
var handle = Addressables.LoadAssetAsync<TextAsset>(nowLoadingScenario);
var jsonStr = handle.WaitForCompletion().ToString();
var jsons = JsonConvert.DeserializeObject<Dictionary<string, object>[]>(jsonStr);
Addressables.Release(handle);
foreach (var x in jsons)
{
previousNode = node;
node = template.CreateDialogueEntry(entryID++, conversation.id, string.Empty);
node.ActorID = lucyID; // Lucy speaks this line.
node.ConversantID = richardID;
int Done = 0;
string nowSequence = "";
foreach (var y in x)
{
string nextSeq = "";
switch (y.Key)
{
case "T":
node.DialogueText = y.Value.ToString();
break;
case "A" or "A_WS":
nextSeq = "AddScenario("
+ nowLoadingScenario + ","
+ y.Value.ToString() + ")";
break;
case "E" or "E_WR":
nextSeq = "EndScenario()";
break;
}
if(y.Key.Contains("WR"))
{
AddSequence(ref nowSequence, nextSeq, Done);
}else if (y.Key.Contains("WS"))
{
AddSequence(ref nowSequence, nextSeq,null, ++Done);
}
else if(!string.IsNullOrEmpty(nextSeq))
{
AddSequence(ref nowSequence, nextSeq);
}
}
if (!string.IsNullOrEmpty(nowSequence) && nowSequence != "")
{
node.Sequence = nowSequence;
Debug.Log($"node.Sequence:{node.Sequence}");
}
conversation.dialogueEntries.Add(node);
// Link from previous node:
link = new Link(conversation.id, previousNode.id, conversation.id, node.id);
previousNode.outgoingLinks.Add(link);
}
while (GameManager.Instance.scenarioProgressing)
{
await UniTask.DelayFrame(1);
}
DialogueManager.StopConversation();
}
private void AddSequence(ref string nowSeq, string add,
int? withReceive = null,int? withSend=null )
{
string newSequence = "";
if (string.IsNullOrEmpty(nowSeq))
{
newSequence = add;
}
else
{
newSequence = nowSeq + add;
}
if (withReceive != null)
{
newSequence += "@" + $"Message(Done{(int)withReceive})";
}
if (withSend != null)
{
newSequence += $"->Message(Done{(int)withSend})";
}
newSequence += ";";
nowSeq = newSequence;
}
}
[My Json (Prologue_Main_Start.json)]
The subject is load next json(Start01.json) and continue to next conversation.
case 1: completable
Code: Select all
[
{
"T": "Text",
"A": "Start01"
},
{
"E": ""
}
]
AddScenario(Prologue_Main_Start,Start01);
EndScenario();
This is possible, but there are restrictions like can not delay ...
case 2: not completable
Code: Select all
[
{
"T": "Text",
"A_WS": "Start01",
"E_WR":""
}
]
AddScenario(Prologue_Main_Start,Start01)->Message(Done1);EndScenario()@Message(Done1);
"@Message" can not receive ...
Best Regards.
IAF