Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            LimitRotation cp = (LimitRotation)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint);
            {
                //affect X/Y/Z
                m_foldoutLimit = EditorGUILayout.Foldout(m_foldoutLimit, "Limits");
                if (m_foldoutLimit)
                {
                    ELimitEuler eLimit   = cp.LimitEuler;
                    Vector3     limitMin = cp.LimitMin;
                    Vector3     limitMax = cp.LimitMax;

                    EConUtil.DrawEulerLimitField(ref eLimit, "X", ref limitMin, ref limitMax, ELimitEuler.X, -180f, 180f);
                    EConUtil.DrawEulerLimitField(ref eLimit, "Y", ref limitMin, ref limitMax, ELimitEuler.Y, -180f, 180f);
                    EConUtil.DrawEulerLimitField(ref eLimit, "Z", ref limitMin, ref limitMax, ELimitEuler.Z, -180f, 180f);

                    cp.LimitEuler = eLimit;
                    cp.LimitMin   = limitMin;
                    cp.LimitMax   = limitMax;

                    GUILayout.Space(5f);
                }

                //space mapping
                //m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                //if (m_foldoutSpace)
                //{
                //    // owner space
                //    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                //    GUILayout.Space(5f);
                //}

                //record modify
                //cp.ModifyInternalData = EditorGUILayout.Toggle(new GUIContent("Modify Internal Data", "This modification will modify the ConstraintStack's internal transform data"), cp.ModifyInternalData);

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Exemplo n.º 2
0
        public static void DrawEulerLimitField(
            ref ELimitEuler eLimit,
            string label,
            ref Vector3 limitMin,
            ref Vector3 limitMax,
            ELimitEuler field,
            float minVal,
            float maxVal)
        {
            bool v = (eLimit & field) != 0;

            EditorGUILayout.BeginHorizontal();
            {
                Rect rc   = GUILayoutUtility.GetRect(16f, 18f);
                bool newV = EditorGUI.Toggle(rc, v);
                if (v != newV)
                {
                    if (newV)
                    {
                        eLimit |= field;
                    }
                    else
                    {
                        eLimit &= (~field);
                    }
                }

                EUtil.PushGUIEnable(newV);
                {
                    float min = 0, max = 0;
                    switch (field)
                    {
                    case ELimitEuler.X: min = limitMin.x; max = limitMax.x; break;

                    case ELimitEuler.Y: min = limitMin.y; max = limitMax.y; break;

                    case ELimitEuler.Z: min = limitMin.z; max = limitMax.z; break;
                    }

                    GUILayout.Label(label);
                    GUILayout.Label("Min");
                    min = Mathf.Clamp(EditorGUILayout.FloatField(min), minVal, maxVal);
                    max = Mathf.Max(max, min);
                    GUILayout.Label(" => ");
                    GUILayout.Label("Max");
                    max = Mathf.Clamp(EditorGUILayout.FloatField(max), minVal, maxVal);
                    min = Mathf.Min(max, min);

                    switch (field)
                    {
                    case ELimitEuler.X: limitMin.x = min; limitMax.x = max; break;

                    case ELimitEuler.Y: limitMin.y = min; limitMax.y = max; break;

                    case ELimitEuler.Z: limitMin.z = min; limitMax.z = max; break;
                    }
                }
                EUtil.PopGUIEnable();
            }
            EditorGUILayout.EndHorizontal();
        }