Ejemplo n.º 1
0
        public void OnGUI()
        {
            EditorGUILayout.BeginHorizontal("Box");
            if (GUILayout.Button("Refresh", GUILayout.MaxWidth(60)))
            {
                AssetDatabase.Refresh();

                TextLocalisation.Refresh();

                dic = TextLocalisation.GetDictionaryForEditor();
            }
            EditorGUILayout.LabelField("Search: ", EditorStyles.boldLabel);
            value = EditorGUILayout.TextField(value);
            EditorGUILayout.EndHorizontal();


            GetSearchResults();
        }
Ejemplo n.º 2
0
        void GetSearchResults()
        {
            if (value == null)
            {
                return;
            }
            Color c = GUI.color;

            EditorGUILayout.BeginVertical();
            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (KeyValuePair <string, string> element in dic)
            {
                if (element.Key.ToLower().Contains(value.ToLower()) || element.Value.ToLower().Contains(value.ToLower()))
                {
                    EditorGUILayout.BeginHorizontal("box");

                    //Draw a delete button
                    Texture    closeIcon = (Texture)Resources.Load("close");
                    Texture    saveIcon  = (Texture)Resources.Load("edit");
                    GUIContent _content  = new GUIContent(closeIcon);


                    GUI.color = Color.red;
                    if (GUILayout.Button(_content, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
                    {
                        if (EditorUtility.DisplayDialog("Remove Key " + element.Key + "?", "This will remove the element from localisation. Are you sure?", "Do It!"))
                        {
                            TextLocalisation.RemoveKey(element.Key);

                            AssetDatabase.Refresh();

                            TextLocalisation.Refresh();

                            dic = TextLocalisation.GetDictionaryForEditor();
                        }
                    }
                    GUI.color = c;

                    _content = new GUIContent(saveIcon);

                    if (GUILayout.Button(_content, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
                    {
                        TextLocaliserGUIEditorEditWindow.Open(element.Key);
                    }

                    EditorGUILayout.TextField(element.Key);
                    EditorGUILayout.LabelField(element.Value);

                    if (this.isDropdown)
                    {
                        GUI.color = Color.yellow;
                        Texture    addIcon = (Texture)Resources.Load("store");
                        GUIContent _add    = new GUIContent(addIcon);

                        if (GUILayout.Button(_add, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
                        {
                            try
                            {
                                GameObject obj = Selection.activeGameObject;

                                if (obj.GetComponent <UITextLocaliser>() != null)
                                {
                                    obj.GetComponent <UITextLocaliser>().key = element.Key;
                                }
                                else
                                {
                                    if (property != null)
                                    {
                                        if (property.FindPropertyRelative("key") != null)
                                        {
                                            property.FindPropertyRelative("key").stringValue = element.Key;
                                        }
                                        else if (property.FindPropertyRelative("text") != null)
                                        {
                                            property.FindPropertyRelative("text").stringValue = element.Key;
                                        }

                                        property.serializedObject.ApplyModifiedProperties();
                                    }
                                }
                            }
                            catch
                            {
                                if (property != null)
                                {
                                    if (property.FindPropertyRelative("key") != null)
                                    {
                                        property.FindPropertyRelative("key").stringValue = element.Key;
                                    }
                                    else if (property.FindPropertyRelative("text") != null)
                                    {
                                        property.FindPropertyRelative("text").stringValue = element.Key;
                                    }

                                    property.serializedObject.ApplyModifiedProperties();
                                }
                            }

                            Close();
                        }
                        GUI.color = c;
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 3
0
 private void OnEnable()
 {
     dic = TextLocalisation.GetDictionaryForEditor();
 }