HKI Core
TextLocalizationEditor.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
3 
4 namespace HKI.Core.Loc.Editor
5 {
9  [CustomEditor(typeof(TextLocalization))]
10  public class TextLocalizationEditor : UnityEditor.Editor
11  {
12  // Private variables
13  const string textLocalizationElementsSPName = "TextLocalizationElements";
14 
15  SerializedProperty textLocalizationElementsSP = null;
16 
17  // On Enable function
18  void OnEnable()
19  {
20  textLocalizationElementsSP = serializedObject.FindProperty(textLocalizationElementsSPName);
21  }
22 
23  // OnInspectorGUI function
24  public override void OnInspectorGUI()
25  {
26  Draw(serializedObject, textLocalizationElementsSP);
27  }
28 
29  // Interface function
30  public static void Draw(SerializedObject serializedObject, SerializedProperty property)
31  {
32  serializedObject.Update();
33 
34  EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
35 
36  if (GUILayout.Button("Add", EditorStyles.toolbarButton, GUILayout.Width(40.0f)))
37  {
38  property.InsertArrayElementAtIndex(property.arraySize);
39 
40  serializedObject.ApplyModifiedProperties();
41  serializedObject.Update();
42  }
43 
44  EditorGUILayout.LabelField("Count of languages: " + property.arraySize);
45 
46  EditorGUILayout.EndHorizontal();
47 
48  bool delete = false;
49  int deleteIndex = 0;
50 
51  for (int i = 0; i < property.arraySize; i++)
52  {
53  EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
54 
55  EditorGUILayout.PropertyField(property.GetArrayElementAtIndex(i));
56 
57  if(GUILayout.Button("Delete", EditorStyles.toolbarButton, GUILayout.Width(70.0f)))
58  {
59  delete = true;
60  deleteIndex = i;
61  }
62 
63 
64  EditorGUILayout.EndHorizontal();
65  }
66 
67  if (delete)
68  property.DeleteArrayElementAtIndex(deleteIndex);
69 
70  serializedObject.ApplyModifiedProperties();
71  }
72  }
73 }
static void Draw(SerializedObject serializedObject, SerializedProperty property)
Custom inspector for the TextLocalization class.