summaryrefslogtreecommitdiff
path: root/Assets/Plugins/Editor/AdvancedInspector/FieldEditors/RigidbodyConstraintsEditor.cs
blob: 781c92b817c32f675e87869122c80c08ba00e899 (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
61
62
63
64
65
66
67
68
69
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;

namespace AdvancedInspector
{
    public class RigidbodyConstraintsEditor : 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(RigidbodyConstraints) }; }
        }

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

            EditorGUI.showMixedValue = field.Mixed;

            EditorGUI.BeginChangeCheck();

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

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

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

            if (GUILayout.Toggle(value.Has(RigidbodyConstraints.FreezePositionZ), "Z", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints.FreezePositionZ;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Freeze Rotation ", GUILayout.Width(LABEL_WIDTH));
            if (GUILayout.Toggle(value.Has(RigidbodyConstraints.FreezeRotationX), "X", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints.FreezeRotationX;

            if (GUILayout.Toggle(value.Has(RigidbodyConstraints.FreezeRotationY), "Y", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints.FreezeRotationY;

            if (GUILayout.Toggle(value.Has(RigidbodyConstraints.FreezeRotationZ), "Z", GUILayout.Width(TOGGLE_WIDTH)))
                newValue += (int)RigidbodyConstraints.FreezeRotationZ;
            EditorGUILayout.EndHorizontal();

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