aboutsummaryrefslogtreecommitdiff
path: root/Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@gmail.com>2019-08-24 15:24:57 -0400
committerAndrew Lee <alee14498@gmail.com>2019-08-24 15:24:57 -0400
commit85553832ead1a96f88726cd2b35cb6ff1d8b8cc8 (patch)
tree7a2615034462d4296ed09d24038bb4c68107979d /Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs
parente06acf066171670248b0b644c0eb8f6d895e051e (diff)
downloadUnicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.gz
Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.bz2
Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.zip
Attempt number 2 on localization
Diffstat (limited to 'Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs')
-rw-r--r--Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs b/Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs
new file mode 100644
index 0000000..740d43d
--- /dev/null
+++ b/Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs
@@ -0,0 +1,54 @@
+using UnityEngine;
+#if UNITY_EDITOR
+using UnityEditor;
+
+namespace Lean.Localization
+{
+ [CustomPropertyDrawer(typeof(LeanTranslationNameAttribute))]
+ public class LeanTranslationNameDrawer : PropertyDrawer
+ {
+ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
+ {
+ var left = position; left.xMax -= 40;
+ var right = position; right.xMin = left.xMax + 2;
+ var color = GUI.color;
+
+ if (LeanLocalization.CurrentTranslations.ContainsKey(property.stringValue) == false)
+ {
+ GUI.color = Color.red;
+ }
+
+ EditorGUI.PropertyField(left, property);
+
+ GUI.color = color;
+
+ if (GUI.Button(right, "List") == true)
+ {
+ var menu = new GenericMenu();
+
+ foreach (var translationName in LeanLocalization.CurrentTranslations.Keys)
+ {
+ menu.AddItem(new GUIContent(translationName), property.stringValue == translationName, () => { property.stringValue = translationName; property.serializedObject.ApplyModifiedProperties(); });
+ }
+
+ if (menu.GetItemCount() > 0)
+ {
+ menu.DropDown(right);
+ }
+ else
+ {
+ Debug.LogWarning("Your scene doesn't contain any phrases, so the phrase name list couldn't be created.");
+ }
+ }
+ }
+ }
+}
+#endif
+
+namespace Lean.Localization
+{
+ /// <summary>This attribute allows you to select a translation from all the localizations in the scene.</summary>
+ public class LeanTranslationNameAttribute : PropertyAttribute
+ {
+ }
+} \ No newline at end of file