- Home /
How can it be that the editor remember the text I added to the dialogue/s ?
The scripts a bit long but they all connected that is why added them all.
I have this editor script: I can change the size of the conversations and dialogues if I filled it and then set the sizes to 0 it will delete all the text I filled. But then when I'm running the game it's showing me the dialogue/s and all texts. I can't figure out how and where did it save it.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
[CustomEditor(typeof(DialogueTrigger))]
public class DialogueTriggerEditor : Editor
{
private SerializedProperty _conversations;
private void OnEnable()
{
_conversations = serializedObject.FindProperty("conversations");
}
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
serializedObject.Update();
_conversations.arraySize = EditorGUILayout.IntField("Conversations Size", _conversations.arraySize);
for (int x = 0; x < _conversations.arraySize; x++)
{
var conversation = _conversations.GetArrayElementAtIndex(x);
var conversationName = conversation.FindPropertyRelative("conversationName");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(conversationName);
EditorGUI.indentLevel++;
var _dialogues = conversation.FindPropertyRelative("Dialogues");
_dialogues.arraySize = EditorGUILayout.IntField("Dialogues size", _dialogues.arraySize);
for (int i = 0; i < _dialogues.arraySize; i++)
{
var dialogue = _dialogues.GetArrayElementAtIndex(i);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(dialogue, new GUIContent("Dialogue " + i), true);
EditorGUI.indentLevel--;
}
if (_dialogues.arraySize > 0)
{
if (GUILayout.Button("Save Conversation"))
{
}
}
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
}
serializedObject.ApplyModifiedProperties();
}
}
Then I have this two classes files:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
{
public string name;
[TextArea(1, 10)]
public List<string> sentences = new List<string>();
}
And
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Conversation
{
public string conversationName;
public List<Dialogue> Dialogues = new List<Dialogue>();
}
And
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
{
public List<Conversation> conversations = new List<Conversation>();
public List<Dialogue> dialogue = new List<Dialogue>();
[HideInInspector]
public int dialogueNum = 0;
private bool triggered = false;
private List<Dialogue> oldDialogue;
private void Start()
{
//oldDialogue = dialogue.ToList();
}
public void TriggerDialogue()
{
if (triggered == false)
{
if (FindObjectOfType<DialogueManager>() != null)
{
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
dialogueNum += 1;
}
triggered = true;
}
}
private void Update()
{
if (DialogueManager.dialogueEnded == true)
{
if (dialogueNum == dialogue.Count)
{
return;
}
else
{
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
DialogueManager.dialogueEnded = false;
dialogueNum += 1;
}
}
}
}
And last:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class DialogueManager : MonoBehaviour { public Text dialogueText; public Text nameText; public float sentencesSwitchDuration; public bool animateSentenceChars = false; public GameObject canvas; public static bool dialogueEnded = false; public DialogueTrigger trigger;
private Queue<string> sentence;
// Use this for initialization
void Start()
{
sentence = new Queue<string>();
}
public void Init()
{
//sentence = new Queue<string>();
}
public void StartDialogue(Dialogue dialogue)
{
canvas.SetActive(true);
nameText.text = dialogue.name;
sentence.Clear();
foreach (string sentence in dialogue.sentences)
{
this.sentence.Enqueue(sentence);
}
DisplayNextSentence();
}
public void DisplayNextSentence()
{
if (this.sentence.Count == 0)
{
EndDialogue();
return;
}
string sentence = this.sentence.Dequeue();
dialogueText.text = sentence;
StopAllCoroutines();
StartCoroutine(DisplayNextSentenceWithDelay(sentence));
}
public IEnumerator DisplayNextSentenceWithDelay(string sentence)
{
if (animateSentenceChars)
{
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
{
dialogueText.text += letter;
yield return null;
}
}
yield return new WaitForSeconds(sentencesSwitchDuration);
DisplayNextSentence();
}
private void EndDialogue()
{
dialogueEnded = true;
if (trigger.dialogueNum == trigger.dialogue.Count)
canvas.SetActive(false);
Debug.Log("End of conversation.");
}
}
I don't want to save it like that. I added the button in the first script:
if (GUILayout.Button("Save Conversation"))
{
}
I'm not sure how yet but this button should save all the conversations, dialogues, name, sentences
My first problem is to understand where and how it saved the dialogue/s if I did not save it ?
Second problem is how can I check if the current dialogue/s of the current conversation name and sentences in the Dialogue class are not empty and then to decide if to enable or disable the button.
Last problem is how to save the whole content to a file: Conversation name , dialogue/s name/s and sentences. And then to add another button to read it back from the file.
Your answer

Follow this Question
Related Questions
How can i check and fire an event when the user look at specific object ? 0 Answers
Sorting a list based of a variable 1 Answer
How can i List objects by name but also in small text or big text or any kind ? 1 Answer
How can i make an entrance and exit in this maze ? 1 Answer
How can I rotate all the objects ? One of them is never rotating 0 Answers