Пример #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position        = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
            position.width -= 48;
            position.height = 18;

            Rect valueRect = new Rect(position);

            valueRect.x     += 15;
            valueRect.width -= 15;

            Rect foldButtonRect = new Rect(position);

            foldButtonRect.width = 15;

            EditorGUI.LabelField(position, "Key", EditorStyles.wordWrappedLabel);

            position.x     += 30;
            position.width -= 80;

            SerializedProperty key = property.FindPropertyRelative("key");

            key.stringValue = EditorGUI.TextField(position, key.stringValue, GetGUIStyle(key.stringValue));

            position.x     += position.width + 2;
            position.width  = 40;
            position.height = 18;

            GUIContent editContent = new GUIContent("edit");

            GUI.enabled = key.stringValue != string.Empty;
            if (GUI.Button(position, editContent))
            {
                TextLocaliserEditWindow.Open(key.stringValue);
            }
            GUI.enabled = true;

            position.x    += position.width + 2;
            position.width = 54;

            GUIContent searchContent = new GUIContent("search");

            if (GUI.Button(position, searchContent))
            {
                TextLocaliserSearchWindow.Open(key);
            }

            EditorGUI.EndProperty();
        }
        public static void Open(string key)
        {
            if (window != null)
            {
                window.Close();
                window = null;
            }

            window = (TextLocaliserEditWindow)CreateInstance(typeof(TextLocaliserEditWindow));
            window.titleContent = new GUIContent("Localiser Window");
            window.ShowUtility();
            window.key = key;

            window.SetCurrentValues();
        }
        void GetSearchResults()
        {
            EditorGUILayout.BeginVertical();
            scroll = EditorGUILayout.BeginScrollView(scroll);
            foreach (KeyValuePair <string, string> element in anyDictionary)
            {
                if (element.Key.ToLower().Contains(value.ToLower()))
                {
                    EditorGUILayout.BeginHorizontal("box");
                    if (GUILayout.Button(element.Key))
                    {
                        sp.stringValue = element.Key;
                        sp.serializedObject.ApplyModifiedProperties();
                        instance.Close();
                    }

                    GUIContent editContent = new GUIContent("edit");

                    if (GUILayout.Button(editContent, GUILayout.MaxWidth(40), GUILayout.MaxHeight(20)))
                    {
                        TextLocaliserEditWindow.Open(element.Key);
                    }

                    GUIContent deleteContent = new GUIContent("delete");

                    if (GUILayout.Button(deleteContent, DeleteGUIStyle(), GUILayout.MaxWidth(55), GUILayout.MaxHeight(20)))
                    {
                        if (EditorUtility.DisplayDialog("Removing key", "Are you sure you want to remove key " + element.Key + "?", "Remove", "Cancel"))
                        {
                            LocalisationManager.Remove(element.Key);
                            AssetDatabase.Refresh();
                            LocalisationManager.Init();
                            anyDictionary = LocalisationManager.GetAnyDictionaryForKeys();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
        public void OnGUI()
        {
            EditorGUILayout.LabelField(key, KeyGUIStyle());

            scroll = EditorGUILayout.BeginScrollView(scroll);

            string[] languages = Enum.GetNames(typeof(Language));
            for (int i = 0; i < languages.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(languages[i] + ": ", GUILayout.MaxWidth(70));

                EditorStyles.textArea.wordWrap = true;
                values[i] = EditorGUILayout.TextArea(values[i], EditorStyles.textArea, GUILayout.Height(50), GUILayout.Width(400));
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Update"))
            {
                for (int i = 0; i < values.Length; i++)
                {
                    if (values[i] == null)
                    {
                        values[i] = string.Empty;
                    }
                    values[i] = values[i].Replace("\n", "\\n");
                }

                LocalisationManager.Replace(key, values);

                window.Close();
                window = null;
            }

            minSize = new Vector2(480, 250);
            maxSize = minSize;
        }