Linking the octo localization system to the dialogue system
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using OctoCore.Localization;
|
||||
|
||||
namespace Unheimlich.Data.Dialogues
|
||||
{
|
||||
@@ -6,13 +7,8 @@ namespace Unheimlich.Data.Dialogues
|
||||
public class DialogueChoiceData
|
||||
{
|
||||
[Header("Choice Content")]
|
||||
[TextArea(2, 5)]
|
||||
[Tooltip("Text displayed on the choice button")]
|
||||
public string ChoiceText;
|
||||
|
||||
[Header("Localization")]
|
||||
[Tooltip("Localization key for the choice text")]
|
||||
public string ChoiceTextLocalizationKey;
|
||||
[Tooltip("Localized text displayed on the choice button")]
|
||||
public OctoLocalizedTextData ChoiceText;
|
||||
|
||||
[Header("Flow")]
|
||||
[Tooltip("Direct reference to the next DialogueNode")]
|
||||
@@ -21,10 +17,18 @@ namespace Unheimlich.Data.Dialogues
|
||||
[Header("Conditions (Optional)")]
|
||||
[Tooltip("Required condition to display this choice (optional, for future use)")]
|
||||
public string RequiredCondition;
|
||||
|
||||
public string GetLocalizedChoiceText()
|
||||
{
|
||||
if (ChoiceText != null)
|
||||
return OctoLocalization.GetLocalizedText(ChoiceText);
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
return !string.IsNullOrEmpty(ChoiceText) && NextNode != null;
|
||||
return ChoiceText != null && NextNode != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OctoCore.Localization;
|
||||
|
||||
namespace Unheimlich.Data.Dialogues
|
||||
{
|
||||
@@ -7,8 +8,8 @@ namespace Unheimlich.Data.Dialogues
|
||||
public class DialogueConversation : ScriptableObject
|
||||
{
|
||||
[Header("Speaker Information")]
|
||||
[Tooltip("Name of the speaker (common to all texts in this conversation)")]
|
||||
public string SpeakerName;
|
||||
[Tooltip("Localized name of the speaker (common to all texts in this conversation)")]
|
||||
public OctoLocalizedTextData SpeakerName;
|
||||
|
||||
[Header("Display Mode")]
|
||||
[Tooltip("Choose how to display dialogue text: World (3D space) or Screen (Canvas UI)")]
|
||||
@@ -17,10 +18,14 @@ namespace Unheimlich.Data.Dialogues
|
||||
[Header("Dialogue Flow")]
|
||||
[Tooltip("Ordered list of dialogue nodes for this conversation")]
|
||||
public List<DialogueNode> DialogueNodes = new List<DialogueNode>();
|
||||
|
||||
[Header("Localization")]
|
||||
[Tooltip("Localization ID for speaker name (optional)")]
|
||||
public string SpeakerNameLocalizationKey;
|
||||
|
||||
public string GetLocalizedSpeakerName()
|
||||
{
|
||||
if (SpeakerName != null)
|
||||
return OctoLocalization.GetLocalizedText(SpeakerName);
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public DialogueNode GetFirstNode()
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OctoCore.Localization;
|
||||
|
||||
namespace Unheimlich.Data.Dialogues
|
||||
{
|
||||
@@ -7,13 +8,8 @@ namespace Unheimlich.Data.Dialogues
|
||||
public class DialogueNode : ScriptableObject
|
||||
{
|
||||
[Header("Content")]
|
||||
[TextArea(3, 10)]
|
||||
[Tooltip("Text displayed for this dialogue node")]
|
||||
public string DialogueText;
|
||||
|
||||
[Header("Localization")]
|
||||
[Tooltip("Localization key for the dialogue text")]
|
||||
public string DialogueTextLocalizationKey;
|
||||
[Tooltip("Localized text displayed for this dialogue node")]
|
||||
public OctoLocalizedTextData DialogueText;
|
||||
|
||||
[Header("Choices")]
|
||||
[Tooltip("List of available choices for this dialogue. If empty, this is an end node")]
|
||||
@@ -22,6 +18,14 @@ namespace Unheimlich.Data.Dialogues
|
||||
[Header("End Node Settings")]
|
||||
[Tooltip("For end nodes (no choices), delay in seconds before automatic close. 0 = requires player interaction to close")]
|
||||
public float AutoCloseDelay = 3f;
|
||||
|
||||
public string GetLocalizedDialogueText()
|
||||
{
|
||||
if (DialogueText != null)
|
||||
return OctoLocalization.GetLocalizedText(DialogueText);
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public bool IsEndNode()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user