The main script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
{
public List<Dialogue> dialogue = new List<Dialogue>();
[HideInInspector]
public int dialogueNum = 0;
private bool triggered = false;
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;
}
}
}
}
The dialogue script that create the items name and sentences:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
{
public string name;
[TextArea(1, 10)]
public string[] sentences;
}
And the editor script:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(DialogueTrigger))]
public class DialogueTriggerEditor : Editor
{
private SerializedProperty _dialogues;
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
_dialogues = serializedObject.FindProperty("dialogue");
serializedObject.Update();
for (int i = 0; i < _dialogues.arraySize; i++)
{
var dialogue = _dialogues.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(dialogue, new GUIContent("Dialogue " + i));
}
}
}
But now I have one variable of the dialogue in the Inspector there I can set the number of dialogues and each dialogue name and sentences.
But under it it's creating more Dialogues according to the number of dialogues I set.
What I want to have instead in the Inspector is one main Dialogues:
Then inside it I can set the number of dialogues. For example if I set 5 then under Dialogues there will be: Dialogue 1 Dialogue 2 Dialogue 3 Dialogue 4 Dialogue 5
And then inside under each Dialogue for example Dialogue 1 there will be the Name and Sentences of it. With the able to change the sentences size of each dialogue.