using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class ConversationTrigger : MonoBehaviour
{
public List<Conversation> conversations = new List<Conversation>();
public GameObject canvas;
public bool conversationEnd = false;
private bool isRunning = false;
[HideInInspector]
public static int conversationIndex;
private DialogueManager dialoguemanager;
private void Start()
{
conversationIndex = 0;
dialoguemanager = FindObjectOfType<DialogueManager>();
}
List<int> conversationsToPlay = new List<int>();
public List<int> StartConversations()
{
for (int i = 0; i < conversationsToPlay.Count; i++)
{
if (!isRunning)
{
StartCoroutine(PlayConversation(conversationsToPlay[i]));
}
}
return conversationsToPlay;
}
public IEnumerator PlayConversation(int index)
{
isRunning = true;
if (conversations.Count > 0 &&
conversations[index].Dialogues.Count > 0)
{
for (int i = 0; i < conversations[index].Dialogues.Count; i++)
{
if (dialoguemanager != null)
{
dialoguemanager.StartDialogue(conversations[index].Dialogues[i]);
}
while (DialogueManager.dialogueEnded == false)
{
yield return null;
}
}
conversationIndex = index;
conversationEnd = true;
canvas.SetActive(false);
Debug.Log("Conversation Ended");
}
isRunning = false;
}
public void SaveConversations()
{
string jsonTransform = JsonHelper.ToJson(conversations.ToArray(), true);
File.WriteAllText(@"d:\json.txt", jsonTransform);
}
public void LoadConversations()
{
string jsonTransform = File.ReadAllText(@"d:\json.txt");
conversations.Clear();
conversations.AddRange(JsonHelper.FromJson<Conversation>(jsonTransform));
}
}
This is the loop part :
List<int> conversationsToPlay = new List<int>();
public List<int> StartConversations()
{
for (int i = 0; i < conversationsToPlay.Count; i++)
{
if (!isRunning)
{
StartCoroutine(PlayConversation(conversationsToPlay[i]));
}
}
return conversationsToPlay;
}
And this is he script where I'm adding the indexs :
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NaviDialogue : MonoBehaviour
{
public ObjectsManipulation op;
public bool scaling = true;
public Scaling scale;
public ConversationTrigger conversationTrigger;
private bool ended = false;
private bool startConversation = false;
private void Start()
{
scaling = true;
op.canScale = false;
}
private void Update()
{
if (scaling == true && DOFControl.hasFinished == true)
{
DOFControl.hasFinished = false;
scaling = false;
op.Scaling();
PlayerController.disablePlayerController = true;
conversationTrigger.StartConversations().Add(0);
conversationTrigger.StartConversations().Add(1);
conversationTrigger.StartConversations().Add(2);
}
The first problem is that it's adding one item then start the conversations. But I want it first to add all the items 0,1,2 and then only to StartConversations.
The second problem is that once it's playing the first conversation it does playing the conversation 0 when it finish the conversation nothing happened and I want it to start playing conversation 1.
The idea is to play conversation 0 after conversation 0 ended start conversation 1 when 1 ended start 2 until it played all the conversations in the list.
So this example :
conversationTrigger.StartConversations().Add(0);
conversationTrigger.StartConversations().Add(1);
conversationTrigger.StartConversations().Add(2);
Should work like : playing the first item when ended play the second item when ended play the last item.
StartConversations
method is ill founded. What is that function supposed to even do? Right now it: (1) gets the conversations to play (2) starts playing them (3) returns the conversations to play so it can be modified. You then do that 3 times. \$\endgroup\$