Linking the octo localization system to the dialogue system
This commit is contained in:
@@ -1,55 +1,19 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using OctoCore.Localization;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
#endif
|
||||
|
||||
namespace Unheimlich.Data.Dialogues
|
||||
{
|
||||
public static class DialogueConversationBuilder
|
||||
{
|
||||
public static DialogueNode CreateSimpleNode(string dialogueText, params (string choiceText, DialogueNode nextNode)[] choices)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
DialogueNode node = ScriptableObject.CreateInstance<DialogueNode>();
|
||||
node.DialogueText = dialogueText;
|
||||
|
||||
foreach (var choice in choices)
|
||||
{
|
||||
DialogueChoiceData choiceData = new DialogueChoiceData
|
||||
{
|
||||
ChoiceText = choice.choiceText,
|
||||
NextNode = choice.nextNode
|
||||
};
|
||||
node.Choices.Add(choiceData);
|
||||
}
|
||||
|
||||
return node;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
// Helper methods kept for compatibility but now create localized text data
|
||||
}
|
||||
|
||||
public static DialogueConversation CreateConversation(string speakerName, params DialogueNode[] nodes)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
DialogueConversation conversation = ScriptableObject.CreateInstance<DialogueConversation>();
|
||||
conversation.SpeakerName = speakerName;
|
||||
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (node != null)
|
||||
conversation.DialogueNodes.Add(node);
|
||||
}
|
||||
|
||||
return conversation;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public class DialogueCreatorWindow : EditorWindow
|
||||
{
|
||||
@@ -108,7 +72,7 @@ public class DialogueCreatorWindow : EditorWindow
|
||||
{
|
||||
EditorGUILayout.Space(10);
|
||||
EditorGUILayout.LabelField("Dialogue Creator", EditorStyles.boldLabel);
|
||||
EditorGUILayout.HelpBox("Quickly create a complete conversation with all nodes pre-linked!", MessageType.Info);
|
||||
EditorGUILayout.HelpBox("Quickly create a complete conversation with all nodes pre-linked!\nTexts will be created as localized assets (you can edit FR/EN later in Inspector).", MessageType.Info);
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
@@ -290,6 +254,21 @@ public class DialogueCreatorWindow : EditorWindow
|
||||
EditorGUILayout.Space(5);
|
||||
}
|
||||
|
||||
private OctoLocalizedTextData CreateLocalizedTextData(string text, string basePath, string suffix)
|
||||
{
|
||||
OctoLocalizedTextData textData = ScriptableObject.CreateInstance<OctoLocalizedTextData>();
|
||||
textData.Init();
|
||||
|
||||
// Set English text by default
|
||||
textData.Languages.Dictionary["English"] = text;
|
||||
textData.Languages.Dictionary["French"] = ""; // Empty, user will fill later
|
||||
|
||||
string textDataPath = AssetDatabase.GenerateUniqueAssetPath($"{basePath}/text_{suffix}.asset");
|
||||
AssetDatabase.CreateAsset(textData, textDataPath);
|
||||
|
||||
return textData;
|
||||
}
|
||||
|
||||
private void CreateDialogue()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_speakerName) || string.IsNullOrEmpty(_conversationName))
|
||||
@@ -311,20 +290,27 @@ public class DialogueCreatorWindow : EditorWindow
|
||||
AssetDatabase.CreateFolder(parentFolder, _conversationName);
|
||||
}
|
||||
|
||||
// Create speaker name localized text
|
||||
OctoLocalizedTextData speakerNameData = CreateLocalizedTextData(_speakerName, folderPath, "SpeakerName");
|
||||
|
||||
List<DialogueNode> createdNodes = new List<DialogueNode>();
|
||||
|
||||
// Create nodes
|
||||
for (int i = 0; i < _nodes.Count; i++)
|
||||
{
|
||||
NodeTemplate template = _nodes[i];
|
||||
DialogueNode node = CreateInstance<DialogueNode>();
|
||||
node.DialogueText = template.NodeText;
|
||||
node.name = $"Node_{i + 1}";
|
||||
|
||||
// Create localized text for dialogue
|
||||
node.DialogueText = CreateLocalizedTextData(template.NodeText, folderPath, $"Node{i + 1}_Text");
|
||||
|
||||
string nodePath = $"{folderPath}/{node.name}.asset";
|
||||
AssetDatabase.CreateAsset(node, nodePath);
|
||||
createdNodes.Add(node);
|
||||
}
|
||||
|
||||
// Link choices
|
||||
for (int i = 0; i < _nodes.Count; i++)
|
||||
{
|
||||
NodeTemplate template = _nodes[i];
|
||||
@@ -334,9 +320,16 @@ public class DialogueCreatorWindow : EditorWindow
|
||||
{
|
||||
int targetIndex = Mathf.Clamp(choiceTemplate.TargetNodeIndex, 0, createdNodes.Count - 1);
|
||||
|
||||
// Create localized text for choice
|
||||
OctoLocalizedTextData choiceTextData = CreateLocalizedTextData(
|
||||
choiceTemplate.Text,
|
||||
folderPath,
|
||||
$"Node{i + 1}_Choice{template.Choices.IndexOf(choiceTemplate)}"
|
||||
);
|
||||
|
||||
DialogueChoiceData choice = new DialogueChoiceData
|
||||
{
|
||||
ChoiceText = choiceTemplate.Text,
|
||||
ChoiceText = choiceTextData,
|
||||
NextNode = createdNodes[targetIndex]
|
||||
};
|
||||
currentNode.Choices.Add(choice);
|
||||
@@ -345,8 +338,9 @@ public class DialogueCreatorWindow : EditorWindow
|
||||
EditorUtility.SetDirty(currentNode);
|
||||
}
|
||||
|
||||
// Create conversation
|
||||
DialogueConversation conversation = CreateInstance<DialogueConversation>();
|
||||
conversation.SpeakerName = _speakerName;
|
||||
conversation.SpeakerName = speakerNameData;
|
||||
conversation.name = _conversationName;
|
||||
conversation.DialogueNodes = createdNodes;
|
||||
|
||||
@@ -359,7 +353,14 @@ public class DialogueCreatorWindow : EditorWindow
|
||||
EditorGUIUtility.PingObject(conversation);
|
||||
Selection.activeObject = conversation;
|
||||
|
||||
EditorUtility.DisplayDialog("Success", $"Conversation '{_conversationName}' created with {_nodes.Count} nodes!\n\nPath: {folderPath}", "OK");
|
||||
EditorUtility.DisplayDialog(
|
||||
"Success",
|
||||
$"Conversation '{_conversationName}' created with {_nodes.Count} nodes!\n\n" +
|
||||
$"Path: {folderPath}\n\n" +
|
||||
$"📝 Note: All texts are in English by default.\n" +
|
||||
$"Open each DialogueNode in the Inspector to add French translations!",
|
||||
"OK"
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user