예제 #1
0
        protected virtual Type GetObjectType(ValueType type)
        {
            switch (type)
            {
            case ValueType.Sprite:
                return(typeof(Sprite));

            case ValueType.Texture2D:
                return(typeof(Texture2D));

            case ValueType.Texture3D:
                return(typeof(Texture3D));

            case ValueType.AudioClip:
                return(typeof(AudioClip));

            case ValueType.VideoClip:
                return(typeof(VideoClip));

            case ValueType.Material:
                return(typeof(Material));

            case ValueType.Font:
                return(typeof(Font));

            case ValueType.GameObject:
                return(typeof(GameObject));

            default:
                return(typeof(Object));
            }
        }
예제 #2
0
        protected virtual void AddEntry(SerializedProperty entries, int index, ValueType type)
        {
            if (index < 0 || index > entries.arraySize)
            {
                return;
            }

            entries.serializedObject.Update();
            entries.InsertArrayElementAtIndex(index);
            SerializedProperty entryProperty = entries.GetArrayElementAtIndex(index);

            var typeProperty   = entryProperty.FindPropertyRelative("type");
            var keyProperty    = entryProperty.FindPropertyRelative("key");
            var valuesProperty = entryProperty.FindPropertyRelative("values");

            keyProperty.stringValue     = string.Empty;
            typeProperty.enumValueIndex = (int)type;

            for (int i = 0; i < valuesProperty.arraySize; i++)
            {
                var valueProperty = valuesProperty.GetArrayElementAtIndex(i);
                valueProperty.FindPropertyRelative("dataValue").stringValue            = null;
                valueProperty.FindPropertyRelative("objectValue").objectReferenceValue = null;
            }

            entries.serializedObject.ApplyModifiedProperties();
            GUI.FocusControl(null);
        }
예제 #3
0
        protected virtual void DrawValueField(Rect rect, SerializedProperty valueProperty, ValueType type, bool multiline = false)
        {
            SerializedProperty objectValue = valueProperty.FindPropertyRelative("objectValue");
            SerializedProperty dataValue   = valueProperty.FindPropertyRelative("dataValue");

            switch (type)
            {
            case ValueType.String:
                string strValue = DataConverter.ToString(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                if (multiline)
                {
                    strValue = EditorGUI.TextArea(rect, strValue, EditorStyles.textArea);
                }
                else
                {
                    strValue = EditorGUI.TextField(rect, GUIContent.none, strValue, EditorStyles.textField);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(strValue);
                }
                break;

            case ValueType.Boolean:
                bool boolValue = DataConverter.ToBoolean(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                boolValue = EditorGUI.Toggle(rect, GUIContent.none, boolValue, EditorStyles.toggle);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(boolValue);
                }
                break;

            case ValueType.Int:
                int intValue = DataConverter.ToInt32(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                intValue = EditorGUI.IntField(rect, GUIContent.none, intValue);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(intValue);
                }
                break;

            case ValueType.Float:
                float floatValue = DataConverter.ToSingle(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                floatValue = EditorGUI.FloatField(rect, GUIContent.none, floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(floatValue);
                }
                break;

            case ValueType.Color:
                Color color = DataConverter.ToColor(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                color = EditorGUI.ColorField(rect, GUIContent.none, color);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(color);
                }
                break;

            case ValueType.Vector2:
                Vector2 vector2 = DataConverter.ToVector2(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                vector2 = EditorGUI.Vector2Field(rect, GUIContent.none, vector2);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(vector2);
                }
                break;

            case ValueType.Vector3:
                Vector3 vector3 = DataConverter.ToVector3(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                vector3 = EditorGUI.Vector3Field(rect, GUIContent.none, vector3);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(vector3);
                }
                break;

            case ValueType.Vector4:
                Vector4 vector4 = DataConverter.ToVector4(dataValue.stringValue);
                EditorGUI.BeginChangeCheck();
                vector4 = EditorGUI.Vector4Field(rect, GUIContent.none, vector4);
                if (EditorGUI.EndChangeCheck())
                {
                    dataValue.stringValue = DataConverter.GetString(vector4);
                }
                break;

            case ValueType.Sprite:
            case ValueType.Texture2D:
            case ValueType.Texture3D:
            case ValueType.AudioClip:
            case ValueType.VideoClip:
            case ValueType.Material:
            case ValueType.Font:
            case ValueType.GameObject:
                var objType = GetObjectType(type);
                objectValue.objectReferenceValue = EditorGUI.ObjectField(rect, GUIContent.none, objectValue.objectReferenceValue, objType, false);
                break;

            default:
                break;
            }
        }
예제 #4
0
        protected virtual void DrawEntryField(Rect position, SerializedProperty entry, int index)
        {
            var keyProperty    = entry.FindPropertyRelative("key");
            var typeProperty   = entry.FindPropertyRelative("type");
            var valuesProperty = entry.FindPropertyRelative("values");

            ValueType type = (ValueType)typeProperty.enumValueIndex;

            float x      = position.x;
            float y      = position.y;
            float height = EditorGUIUtility.singleLineHeight;
            float width  = position.width - HORIZONTAL_GAP * 2;

            Rect foldoutRect = new Rect(x + 15, y, 16, 16);
            var  foldout     = index == foldoutIndex;

            EditorGUI.BeginChangeCheck();
            foldout = EditorGUI.Foldout(foldoutRect, foldout, GUIContent.none);
            if (EditorGUI.EndChangeCheck())
            {
                foldoutIndex         = foldout ? index : -1;
                this.entryList.index = foldoutIndex;
            }

            if (foldoutIndex != index)
            {
                Rect keyRect   = new Rect(foldoutRect.xMax - 15, y, Mathf.Min(200, width * 0.4f), height);
                Rect typeRect  = new Rect(keyRect.xMax + HORIZONTAL_GAP, y, Mathf.Min(120, width * 0.2f), height);
                Rect valueRect = new Rect(typeRect.xMax + HORIZONTAL_GAP, y, position.xMax - typeRect.xMax - HORIZONTAL_GAP, height);

                EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none);
                EditorGUI.LabelField(typeRect, type.ToString());
                if (this.currLanguageIndex >= this.languages.Count)
                {
                    this.currLanguageIndex = 0;
                }

                var valueProperty = valuesProperty.GetArrayElementAtIndex(this.currLanguageIndex);
                DrawValueField(valueRect, valueProperty, type);
            }
            else
            {
                y    += height + VERTICAL_GAP;
                width = position.width + 40;
                Rect keyLabelRect = new Rect(x, y, Mathf.Min(200, width * 0.4f), height);
                Rect keyRect      = new Rect(keyLabelRect.xMax + HORIZONTAL_GAP, y, width - keyLabelRect.width - HORIZONTAL_GAP, height);
                EditorGUI.LabelField(keyLabelRect, "Key");
                EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none);

                y += height + VERTICAL_GAP;

                Rect typeLabelRect = new Rect(x, y, Mathf.Min(200, width * 0.4f), height);
                Rect typeRect      = new Rect(typeLabelRect.xMax + HORIZONTAL_GAP, y, width - typeLabelRect.width - HORIZONTAL_GAP, height);
                EditorGUI.LabelField(typeLabelRect, "Type");
                EditorGUI.LabelField(typeRect, type.ToString());

                y += height + VERTICAL_GAP;

                float valueHeight = type == ValueType.String ? height * 2 : height;

                for (int i = 0; i < languages.Count; i++)
                {
                    Rect languageRect = new Rect(x, y, Mathf.Min(200, width * 0.4f), height);
                    Rect valueRect    = new Rect(languageRect.xMax + HORIZONTAL_GAP, y, position.xMax - languageRect.xMax - HORIZONTAL_GAP, valueHeight);

                    Language language      = Language.GetLanguage(languages[i]);
                    var      valueProperty = valuesProperty.GetArrayElementAtIndex(i);

                    string languageContent = string.Format("{0} [{1}]", language.Name, language.Code);
                    if (!string.IsNullOrEmpty(language.Country))
                    {
                        languageContent = string.Format("{0}({1}) [{2}]", language.Name, language.Country, language.Code);
                    }

                    EditorGUI.LabelField(languageRect, new GUIContent(languageContent, languageContent));
                    DrawValueField(valueRect, valueProperty, type, true);

                    y += valueHeight + VERTICAL_GAP;
                }

                this.elementHeight = y - position.y + 5;
            }
        }
예제 #5
0
        protected virtual void DrawEntryField(Rect position, SerializedProperty entry, int index)
        {
            var keyProperty   = entry.FindPropertyRelative("key");
            var typeProperty  = entry.FindPropertyRelative("type");
            var valueProperty = entry.FindPropertyRelative("value");

            ValueType type = (ValueType)typeProperty.enumValueIndex;

            float x      = position.x;
            float y      = position.y;
            float height = EditorGUIUtility.singleLineHeight;
            float width  = position.width - HORIZONTAL_GAP * 2;

            Rect foldoutRect = new Rect(x + 15, y, 16, 16);
            var  foldout     = index == foldoutIndex;

            EditorGUI.BeginChangeCheck();
            foldout = EditorGUI.Foldout(foldoutRect, foldout, GUIContent.none);
            if (EditorGUI.EndChangeCheck())
            {
                this.foldoutIndex    = foldout ? index : -1;
                this.entryList.index = foldoutIndex;
            }

            if (foldoutIndex != index)
            {
                Rect keyRect   = new Rect(foldoutRect.xMax - 15, y, Mathf.Min(200, width * 0.4f), height);
                Rect typeRect  = new Rect(keyRect.xMax + HORIZONTAL_GAP, y, Mathf.Min(120, width * 0.2f), height);
                Rect valueRect = new Rect(typeRect.xMax + HORIZONTAL_GAP, y, position.xMax - typeRect.xMax - HORIZONTAL_GAP, height);

                EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none);

                EditorGUI.LabelField(typeRect, type.ToString());
                DrawValueField(valueRect, valueProperty, type);
            }
            else
            {
                y    += height + VERTICAL_GAP;
                width = position.width + 40;

                Rect keyLabelRect = new Rect(x, y, Mathf.Min(60, width * 0.2f), height);
                Rect keyRect      = new Rect(keyLabelRect.xMax + HORIZONTAL_GAP, y, width - keyLabelRect.width - HORIZONTAL_GAP, height);
                EditorGUI.LabelField(keyLabelRect, "Key");
                EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none);

                y += height + VERTICAL_GAP;

                Rect typeLabelRect = new Rect(x, y, Mathf.Min(60, width * 0.2f), height);
                Rect typeRect      = new Rect(typeLabelRect.xMax + HORIZONTAL_GAP, y, width - typeLabelRect.width - HORIZONTAL_GAP, height);
                EditorGUI.LabelField(typeLabelRect, "Type");
                EditorGUI.LabelField(typeRect, type.ToString());

                y += height + VERTICAL_GAP;

                float valueHeight    = type == ValueType.String ? height * 4 : height;
                Rect  valueLabelRect = new Rect(x, y, Mathf.Min(60, width * 0.2f), height);
                Rect  valueRect      = new Rect(valueLabelRect.xMax + HORIZONTAL_GAP, y, width - valueLabelRect.width - HORIZONTAL_GAP, valueHeight);
                EditorGUI.LabelField(valueLabelRect, "Value");
                DrawValueField(valueRect, valueProperty, type, true);

                y += valueHeight + VERTICAL_GAP;

                this.elementHeight = y - position.y + 5;
            }
        }