Re: Substring replacement
Posted: Wed Nov 02, 2022 3:25 pm
Here's an example scene:
DS_AddResponsesExample_2022-11-02.unitypackage
It uses this script:
DS_AddResponsesExample_2022-11-02.unitypackage
It uses this script:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class AddResponsesExample : MonoBehaviour
{
public List<GameObject> visitors;
private void Awake()
{
Lua.RegisterFunction(nameof(MakeVisitorList), this, SymbolExtensions.GetMethodInfo(() => MakeVisitorList()));
}
private void MakeVisitorList()
{
Debug.Log("Making visitor list:");
// Get the current entry ID: (This is a special Lua variable in the Dialogue System.)
var entryID = Lua.Run("return thisID").asInt;
// Get the current conversation & entry:
var database = DialogueManager.masterDatabase;
var conversation = database.GetConversation(DialogueManager.lastConversationID);
var entry = database.GetDialogueEntry(conversation.id, entryID);
// Remove old outgoing entries:
foreach (var link in entry.outgoingLinks)
{
var responseEntry = database.GetDialogueEntry(link);
conversation.dialogueEntries.Remove(responseEntry);
}
entry.outgoingLinks.Clear();
// Add new outgoing entries:
var template = Template.FromDefault();
foreach (var visitor in visitors)
{
if (visitor.activeInHierarchy)
{
Debug.Log($"Adding visitor: {visitor.name}");
entry.DialogueText += $"\n{visitor.name}";
var responseEntry = template.CreateDialogueEntry(template.GetNextDialogueEntryID(conversation), conversation.id, visitor.name);
responseEntry.ActorID = entry.ConversantID; // Assign to player.
responseEntry.MenuText = $"Approach {visitor.name}";
responseEntry.DialogueText = $"You approach {visitor.name}.";
conversation.dialogueEntries.Add(responseEntry);
entry.outgoingLinks.Add(new Link(conversation.id, entry.id, conversation.id, responseEntry.id));
}
}
Debug.Log("--end of list--");
}
}