diff options
| author | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
| commit | 85553832ead1a96f88726cd2b35cb6ff1d8b8cc8 (patch) | |
| tree | 7a2615034462d4296ed09d24038bb4c68107979d /Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs | |
| parent | e06acf066171670248b0b644c0eb8f6d895e051e (diff) | |
| download | Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.gz Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.bz2 Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.zip | |
Attempt number 2 on localization
Diffstat (limited to 'Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs')
| -rw-r--r-- | Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs b/Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs new file mode 100644 index 0000000..e613d38 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs @@ -0,0 +1,46 @@ +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; + +namespace Lean.Localization +{ + [CustomPropertyDrawer(typeof(LeanLanguageNameAttribute))] + public class LeanLanguageNameDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + var rectA = position; rectA.xMax -= 37.0f; + var rectB = position; rectB.xMin = rectB.xMax - 35.0f; + + EditorGUI.PropertyField(rectA, property); + + if (GUI.Button(rectB, "List") == true) + { + var menu = new GenericMenu(); + + foreach (var languageName in LeanLocalization.CurrentLanguages.Keys) + { + menu.AddItem(new GUIContent(languageName), property.stringValue == languageName, () => { property.stringValue = languageName; property.serializedObject.ApplyModifiedProperties(); }); + } + + if (menu.GetItemCount() > 0) + { + menu.DropDown(rectB); + } + else + { + Debug.LogWarning("Your scene doesn't contain any languages, so the language name list couldn't be created."); + } + } + } + } +} +#endif + +namespace Lean.Localization +{ + /// <summary>This attribute allows you to modify a normal string field into one that has a dropdown list that allows you to pick a language.</summary> + public class LeanLanguageNameAttribute : PropertyAttribute + { + } +}
\ No newline at end of file |
