From f5e1c89936c7b337dc414800839ddcbcc319b9c2 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 8 Apr 2015 21:38:13 +0100 Subject: [PATCH] Flowcharts use a localisation id property when exporting strings #8 --- Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs | 3 +++ Assets/Fungus/Flowchart/Scripts/Flowchart.cs | 6 ++++++ Assets/Fungus/Flowchart/Scripts/Language.cs | 14 ++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs b/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs index 09585f73..ccd4b8a2 100644 --- a/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs @@ -23,6 +23,7 @@ namespace Fungus protected SerializedProperty hideComponentsProp; protected SerializedProperty runSlowDurationProp; protected SerializedProperty saveSelectionProp; + protected SerializedProperty localizationIdProp; protected SerializedProperty variablesProp; protected virtual void OnEnable() @@ -32,6 +33,7 @@ namespace Fungus hideComponentsProp = serializedObject.FindProperty("hideComponents"); runSlowDurationProp = serializedObject.FindProperty("runSlowDuration"); saveSelectionProp = serializedObject.FindProperty("saveSelection"); + localizationIdProp = serializedObject.FindProperty("localizationId"); variablesProp = serializedObject.FindProperty("variables"); } @@ -48,6 +50,7 @@ namespace Fungus EditorGUILayout.PropertyField(hideComponentsProp); EditorGUILayout.PropertyField(runSlowDurationProp); EditorGUILayout.PropertyField(saveSelectionProp); + EditorGUILayout.PropertyField(localizationIdProp); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index efd3bb55..c6d117df 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -109,6 +109,12 @@ namespace Fungus [Tooltip("Saves the selected block and commands when saving the scene.")] public bool saveSelection = true; + /** + * Unique identifier for identifying this flowchart in localized string keys. + */ + [Tooltip("Unique identifier for this flowchart in localized string keys. An id must be provided for Language string export to work.")] + public string localizationId = ""; + /** * Unique id to assign to the next created item. * Increases monotonically every time a new item is added to the Flowchart. diff --git a/Assets/Fungus/Flowchart/Scripts/Language.cs b/Assets/Fungus/Flowchart/Scripts/Language.cs index 79513937..08b12743 100644 --- a/Assets/Fungus/Flowchart/Scripts/Language.cs +++ b/Assets/Fungus/Flowchart/Scripts/Language.cs @@ -112,6 +112,12 @@ namespace Fungus Flowchart[] flowcharts = GameObject.FindObjectsOfType(); foreach (Flowchart flowchart in flowcharts) { + // Have to set a unique localization id to export strings + if (flowchart.localizationId.Length == 0) + { + continue; + } + Block[] blocks = flowchart.GetComponentsInChildren(); foreach (Block block in blocks) { @@ -124,14 +130,14 @@ namespace Fungus System.Type type = command.GetType(); if (type == typeof(Say)) { - stringID = "SAY." + flowchart.name + "." + command.itemId; + stringID = "SAY." + flowchart.localizationId + "." + command.itemId; Say sayCommand = command as Say; standardText = sayCommand.storyText; description = sayCommand.description; } else if (type == typeof(Menu)) { - stringID = "MENU." + flowchart.name + "." + command.itemId; + stringID = "MENU." + flowchart.localizationId + "." + command.itemId; Menu menuCommand = command as Menu; standardText = menuCommand.text; description = menuCommand.description; @@ -233,7 +239,7 @@ namespace Fungus // Parse header row string[] columnNames = csvTable[0]; - if (columnNames.Length < 5) + if (columnNames.Length < 4) { // No languages defined in CSV file return; @@ -259,7 +265,7 @@ namespace Fungus Dictionary flowchartDict = new Dictionary(); foreach (Flowchart flowChart in GameObject.FindObjectsOfType()) { - flowchartDict[flowChart.name] = flowChart; + flowchartDict[flowChart.localizationId] = flowChart; } for (int i = 1; i < csvTable.Length; ++i)