80 lines
3.0 KiB
C#
80 lines
3.0 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
using Unheimlich.Data.Dialogues;
|
|
|
|
[CustomEditor(typeof(DialogueConversation))]
|
|
public class DialogueConversationEditor : Editor
|
|
{
|
|
private SerializedProperty _speakerNameProp;
|
|
private SerializedProperty _speakerNameLocalizationKeyProp;
|
|
private SerializedProperty _dialogueNodesProp;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_speakerNameProp = serializedObject.FindProperty("SpeakerName");
|
|
_speakerNameLocalizationKeyProp = serializedObject.FindProperty("SpeakerNameLocalizationKey");
|
|
_dialogueNodesProp = serializedObject.FindProperty("DialogueNodes");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
EditorGUILayout.LabelField("Conversation Setup", EditorStyles.boldLabel);
|
|
EditorGUILayout.PropertyField(_speakerNameProp);
|
|
EditorGUILayout.PropertyField(_speakerNameLocalizationKeyProp, new GUIContent("Localization Key (Optional)"));
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
EditorGUILayout.LabelField("Dialogue Flow", EditorStyles.boldLabel);
|
|
EditorGUILayout.HelpBox("The first DialogueNode in the list will be the starting point of the conversation.", MessageType.Info);
|
|
|
|
EditorGUILayout.PropertyField(_dialogueNodesProp, new GUIContent("Dialogue Nodes"), true);
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
if (GUILayout.Button("Create New Dialogue Node", GUILayout.Height(30)))
|
|
CreateNewDialogueNode();
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
DialogueConversation conversation = (DialogueConversation)target;
|
|
if (conversation.DialogueNodes != null && conversation.DialogueNodes.Count > 0)
|
|
{
|
|
EditorGUILayout.LabelField("Conversation Overview", EditorStyles.boldLabel);
|
|
EditorGUILayout.LabelField($"Total Nodes: {conversation.DialogueNodes.Count}");
|
|
|
|
DialogueNode firstNode = conversation.GetFirstNode();
|
|
if (firstNode != null)
|
|
EditorGUILayout.LabelField($"Starting Node: {firstNode.name}");
|
|
}
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
|
|
private void CreateNewDialogueNode()
|
|
{
|
|
DialogueConversation conversation = (DialogueConversation)target;
|
|
|
|
string path = AssetDatabase.GetAssetPath(conversation);
|
|
string directory = System.IO.Path.GetDirectoryName(path);
|
|
|
|
DialogueNode newNode = ScriptableObject.CreateInstance<DialogueNode>();
|
|
newNode.name = $"Node_{conversation.DialogueNodes.Count + 1}";
|
|
|
|
string nodePath = AssetDatabase.GenerateUniqueAssetPath($"{directory}/{newNode.name}.asset");
|
|
AssetDatabase.CreateAsset(newNode, nodePath);
|
|
|
|
conversation.DialogueNodes.Add(newNode);
|
|
|
|
EditorUtility.SetDirty(conversation);
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
|
|
EditorGUIUtility.PingObject(newNode);
|
|
}
|
|
}
|