aboutsummaryrefslogtreecommitdiff
path: root/Assets/Packages/Lean/Localization/Scripts/LeanLanguageNameAttribute.cs
blob: e613d389f4ae7bdadee0ed5f3e6a2462b6b0363d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
	{
	}
}