summaryrefslogtreecommitdiff
path: root/Assets/Plugins/Editor/AdvancedInspector/FieldEditors/RigidbodyConstraints2DEditor.cs
blob: 4e54cbaaa37d69036609949de9cb9fffd713522e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;

namespace AdvancedInspector
{
    public class RigidbodyConstraints2DEditor : FieldEditor
    {
        private const int LABEL_WIDTH = 96;
        private const int TOGGLE_WIDTH = 28;

        public override bool EditDerived
        {
            get { return false; }
        }

        public override bool Expandable
        {
            get { return true; }
        }

        public override Type[] EditedTypes
        {
            get { return new Type[] { typeof(RigidbodyConstraints2D) }; }
        }

        public override void Draw(InspectorField field, GUIStyle style)
        {
            field.Expandable = true;
            if (!field.Expanded)
                return;

            EditorGUI.showMixedValue = field.Mixed;

            EditorGUI.BeginChangeCheck();

            RigidbodyConstraints2D value = (RigidbodyConstraints2D)GetValue(field);
            int newValue = 0;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Freeze Position ", GUILayout.Width(LABEL_WIDTH));
            if (GUILayout.Toggle(value.Has(RigidbodyConstraints2D.FreezePositionX), "X", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints2D.FreezePositionX;

            if (GUILayout.Toggle(value.Has(RigidbodyConstraints2D.FreezePositionY), "Y", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints2D.FreezePositionY;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Freeze Rotation ", GUILayout.Width(LABEL_WIDTH));
            if (GUILayout.Toggle(value.Has(RigidbodyConstraints2D.FreezeRotation), "Z", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints2D.FreezeRotation;
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
                field.SetValue(Enum.ToObject(typeof(RigidbodyConstraints2D), newValue));
        }
    }
}