protected override object DrawInternal(Rect rect)
        {
            GUI.SetNextControlName(fieldName.text);
            var a       = (T2)value;
            var keyName = _keyField.GetValue(value) as string;

            LocalizationEditorUtility.DrawLanguagePicker(ref rect, keyName, (newKeyName) =>
            {
                _keyField.SetValue(value, newKeyName);
            });

            EditorGUI.BeginChangeCheck();
            if (LocalizationManager.currentDatabase != null && LocalizationManager.currentDatabase.ContainsObject(keyName) == false)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.5f);
            }

            var obj = EditorGUI.ObjectField(GetSingleLineHeightRect(rect), fieldName, a.objectVal, typeof(T), false);

            if (EditorGUI.EndChangeCheck() && LocalizationManager.defaultDatabase != null && obj != LocalizationManager.defaultDatabase.GetObject <T>(keyName))
            {
                if (IsNullOrWhiteSpace(keyName) || keyName == LocalizationManager.NoKeyConstant)
                {
                    _keyField.SetValue(value, LocalizationManager.CreateNewObjectKey <T>());
                    NotifyValueChanged(value);
                }

                a.objectVal = obj;
                NotifyValueChanged(a);
            }

            GUI.color = Color.white;
            return(a);
        }
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(rect, label, property);

            var keyField = property.FindPropertyRelative("_key");
            var inst     = (ILocalizedObject)CreateDefaultObject <T2>(keyField.stringValue);

            LocalizationEditorUtility.DrawLanguagePicker(ref rect, keyField.stringValue, (newKeyName) =>
            {
                keyField.stringValue = newKeyName;
            });

            if (LocalizationManager.currentDatabase != null && LocalizationManager.currentDatabase.ContainsObject(keyField.stringValue) == false)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.5f);
            }

            EditorGUI.BeginChangeCheck();
            rect.height = EditorGUIUtility.singleLineHeight;
            var obj = (T)EditorGUI.ObjectField(rect, label, inst.objectVal, typeof(T), false);

            if (EditorGUI.EndChangeCheck() && LocalizationManager.defaultDatabase != null)
            {
                if (obj != LocalizationManager.defaultDatabase.GetObject <T>(keyField.stringValue))
                {
                    if (IsNullOrWhiteSpace(keyField.stringValue) || keyField.stringValue == LocalizationManager.NoKeyConstant)
                    {
                        keyField.stringValue = LocalizationManager.CreateNewObjectKey <T>(obj);
                    }
                }

                inst.objectVal = obj;
                GUI.changed    = true;
            }

            GUI.color = Color.white;
            EditorGUI.EndProperty();
        }
Example #3
0
        protected override object DrawInternal(Rect rect)
        {
            GUI.SetNextControlName(fieldName.text);
            var a       = (LocalizedString)value;
            var keyName = _keyField.GetValue(value) as string;

            if (_textArea != null)
            {
                EditorGUI.LabelField(rect, fieldName);
                rect.y += ReflectionDrawerStyles.singleLineHeight;

                LocalizationEditorUtility.DrawLanguagePicker(ref rect, keyName, (newKeyName) =>
                {
                    _keyField.SetValue(value, newKeyName);
                });

                rect.height = ReflectionDrawerStyles.singleLineHeight * Mathf.Max(_textArea.maxLines, 3);

                EditorGUI.BeginChangeCheck();

                if (LocalizationManager.currentDatabase != null && LocalizationManager.currentDatabase.ContainsString(keyName) == false)
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                }

                var str2 = EditorGUI.TextArea(rect, a.message ?? "");
                if (EditorGUI.EndChangeCheck() && LocalizationManager.defaultDatabase != null && str2 != LocalizationManager.defaultDatabase.GetString(keyName))
                {
                    if (IsNullOrWhiteSpace(keyName) || keyName == LocalizationManager.NoKeyConstant)
                    {
                        _keyField.SetValue(value, LocalizationManager.CreateNewStringKey());
                        NotifyValueChanged(value);
                    }

                    a.message = str2;
                    NotifyValueChanged(a);
                }

                GUI.color = Color.white;
                return(a);
            }


            LocalizationEditorUtility.DrawLanguagePicker(ref rect, keyName, (newKeyName) =>
            {
                _keyField.SetValue(value, newKeyName);
            });

            EditorGUI.BeginChangeCheck();

            if (LocalizationManager.currentDatabase != null && LocalizationManager.currentDatabase.ContainsString(keyName) == false)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.5f);
            }

            var str = EditorGUI.TextField(GetSingleLineHeightRect(rect), fieldName, a.message ?? "");

            if (EditorGUI.EndChangeCheck() && LocalizationManager.defaultDatabase != null && str != LocalizationManager.defaultDatabase.GetString(keyName))
            {
                if (IsNullOrWhiteSpace(keyName) || keyName == LocalizationManager.NoKeyConstant)
                {
                    _keyField.SetValue(value, LocalizationManager.CreateNewStringKey());
                    NotifyValueChanged(value);
                }

                a.message = str;
                NotifyValueChanged(a);
            }

            GUI.color = Color.white;
            return(a);
        }
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(rect, label, property);

            var keyField = property.FindPropertyRelative("_key");
            var msgInst  = new LocalizedString(keyField.stringValue);

            if (_textArea != null)
            {
                EditorGUI.LabelField(rect, label);
                rect.y += ReflectionDrawerStyles.singleLineHeight;

                LocalizationEditorUtility.DrawLanguagePicker(ref rect, keyField.stringValue, (newKeyName) =>
                {
                    keyField.stringValue = newKeyName;
                });

                rect.height = ReflectionDrawerStyles.singleLineHeight * Mathf.Max(_textArea.maxLines, 3);

                EditorGUI.BeginChangeCheck();

                if (LocalizationManager.currentDatabase != null && LocalizationManager.currentDatabase.ContainsString(keyField.stringValue) == false)
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                }

                var str2 = EditorGUI.TextArea(rect, msgInst.message ?? "");
                if (EditorGUI.EndChangeCheck() && LocalizationManager.defaultDatabase != null && str2 != LocalizationManager.defaultDatabase.GetString(keyField.stringValue))
                {
                    if (IsNullOrWhiteSpace(keyField.stringValue) || keyField.stringValue == LocalizationManager.NoKeyConstant)
                    {
                        keyField.stringValue = LocalizationManager.CreateNewStringKey();
                    }

                    msgInst.message = str2;
                }

                GUI.color = Color.white;
                return;
            }

            LocalizationEditorUtility.DrawLanguagePicker(ref rect, keyField.stringValue, (newKeyName) =>
            {
                keyField.stringValue = newKeyName;
            });
            EditorGUI.BeginChangeCheck();

            if (LocalizationManager.currentDatabase != null && LocalizationManager.currentDatabase.ContainsString(keyField.stringValue) == false)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.5f);
            }

            rect.height = EditorGUIUtility.singleLineHeight;
            var str = EditorGUI.TextField(rect, label, msgInst.message ?? "");

            if (EditorGUI.EndChangeCheck() && LocalizationManager.defaultDatabase != null && str != LocalizationManager.defaultDatabase.GetString(keyField.stringValue))
            {
                if (IsNullOrWhiteSpace(keyField.stringValue) || keyField.stringValue == LocalizationManager.NoKeyConstant)
                {
                    keyField.stringValue = LocalizationManager.CreateNewStringKey();
                }

                msgInst.message = str;
            }

            GUI.color = Color.white;
            EditorGUI.EndProperty();
        }