aboutsummaryrefslogtreecommitdiff
path: root/Assets/Packages/Lean/Localization/Scripts/LeanTranslationNameAttribute.cs
blob: 740d43de6d996c1cb39390e3dd117a86a44ef6e0 (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
47
48
49
50
51
52
53
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
	{
	}
}