97 lines
3.1 KiB
C#
97 lines
3.1 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using Unheimlich.Data.Dialogues;
|
|
|
|
[CustomEditor(typeof(DialogueNode))]
|
|
public class DialogueNodeEditor : Editor
|
|
{
|
|
private SerializedProperty _dialogueTextProp;
|
|
private SerializedProperty _choicesProp;
|
|
private SerializedProperty _autoCloseDelayProp;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_dialogueTextProp = serializedObject.FindProperty("DialogueText");
|
|
_choicesProp = serializedObject.FindProperty("Choices");
|
|
_autoCloseDelayProp = serializedObject.FindProperty("AutoCloseDelay");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
EditorGUILayout.LabelField("Node Content", EditorStyles.boldLabel);
|
|
EditorGUILayout.PropertyField(_dialogueTextProp);
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
EditorGUILayout.LabelField("Choices", EditorStyles.boldLabel);
|
|
|
|
DialogueNode node = (DialogueNode)target;
|
|
|
|
if (node.IsEndNode())
|
|
{
|
|
EditorGUILayout.HelpBox("This node is an end of conversation (no choices).", MessageType.Info);
|
|
|
|
EditorGUILayout.Space(5);
|
|
EditorGUILayout.LabelField("End Node Settings", EditorStyles.boldLabel);
|
|
EditorGUILayout.PropertyField(_autoCloseDelayProp, new GUIContent("Auto Close Delay (seconds)"));
|
|
|
|
float delay = _autoCloseDelayProp.floatValue;
|
|
if (delay > 0)
|
|
EditorGUILayout.HelpBox($"The dialogue will automatically close after {delay:F1}s with a fade out.", MessageType.None);
|
|
else
|
|
EditorGUILayout.HelpBox("Player must press 'Interact' to close the dialogue.", MessageType.None);
|
|
|
|
EditorGUILayout.Space(5);
|
|
}
|
|
else if (!node.HasValidChoices())
|
|
EditorGUILayout.HelpBox("Warning: Some choices don't have a NextNode assigned.", MessageType.Warning);
|
|
|
|
EditorGUILayout.PropertyField(_choicesProp, true);
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
if (GUILayout.Button("Add Choice"))
|
|
{
|
|
AddNewChoice();
|
|
}
|
|
|
|
if (node.Choices != null && node.Choices.Count > 0)
|
|
{
|
|
if (GUILayout.Button("Clear All Choices"))
|
|
{
|
|
if (EditorUtility.DisplayDialog("Clear Choices",
|
|
"Are you sure you want to remove all choices?",
|
|
"Yes", "Cancel"))
|
|
{
|
|
node.Choices.Clear();
|
|
EditorUtility.SetDirty(node);
|
|
}
|
|
}
|
|
}
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
|
|
private void AddNewChoice()
|
|
{
|
|
DialogueNode node = (DialogueNode)target;
|
|
|
|
DialogueChoiceData newChoice = new DialogueChoiceData
|
|
{
|
|
ChoiceText = null, // Will need to assign OctoLocalizedTextData manually
|
|
NextNode = null
|
|
};
|
|
|
|
node.Choices.Add(newChoice);
|
|
EditorUtility.SetDirty(node);
|
|
}
|
|
}
|