Example #1
0
        private static void DragSustainValue(Rect rect, SerializedProperty property)
        {
            Event evt = Event.current;
            int   id  = GUIUtility.GetControlID(sustainHash, FocusType.Passive, rect);

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (rect.Contains(evt.mousePosition) && evt.button == 0)
                {
                    GUIUtility.hotControl = id;
                    dragStartValue        = property.FindPropertyRelative(nameof(Envelope.sustainValue)).floatValue;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.hotControl == id && evt.keyCode == KeyCode.Escape)
                {
                    SerializedEnvelopeHelpers.UpdateSustainValue(property, dragStartValue);
                    GUI.changed           = true;
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeVertical);
                break;
            }

            if (evt.isMouse && GUIUtility.hotControl == id)
            {
                float relativeY = evt.mousePosition.y - rect.y;
                float value     = Mathf.Clamp01(1 - (relativeY / rect.height));
                SerializedEnvelopeHelpers.UpdateSustainValue(property, value);
                GUI.changed = true;
                Event.current.Use();
            }
        }
Example #2
0
        private static Rect DrawReleaseGraph(SerializedProperty property, Rect rect, float totalWidth)
        {
            EditorGUI.BeginChangeCheck();
            var releaseTime = property.FindPropertyRelative(nameof(Envelope.releaseTime)).floatValue;

            rect.width = releaseTime * totalWidth + minGraphWidth;
            var            inputCurve = property.FindPropertyRelative(nameof(Envelope.releaseCurve)).animationCurveValue;
            AnimationCurve curveValue = EditorGUI.CurveField(
                rect,
                inputCurve,
                releaseColor,
                ranges
                );

            if (EditorGUI.EndChangeCheck())
            {
                SerializedEnvelopeHelpers.UpdateReleaseCurve(property, curveValue);
            }
            DrawGraphCaption(rect, property.FindPropertyRelative(nameof(Envelope.releaseCurve)), new GUIContent("Release"));

            rect.x += rect.width;
            return(rect);
        }
Example #3
0
        static void DrawSustainValue(Rect rect, SerializedProperty prop)
        {
            float gap           = 12;
            float checkboxWidth = 64;
            Rect  valueRect     = rect;

            valueRect.width = rect.width - checkboxWidth - gap;
            EditorGUI.BeginChangeCheck();
            SerializedProperty sustainValueProp = prop.FindPropertyRelative(nameof(Envelope.sustainValue));

            EditorGUI.PropertyField(valueRect, sustainValueProp);
            if (EditorGUI.EndChangeCheck())
            {
                float safeValue = Mathf.Clamp01(sustainValueProp.floatValue);
                SerializedEnvelopeHelpers.UpdateSustainValue(prop, safeValue);
            }

            Rect checkboxRect = rect;

            checkboxRect.width = checkboxWidth;
            checkboxRect.x     = valueRect.xMax + gap;

            var label = new GUIContent("Hold");
            SerializedProperty holdSustainProp = prop.FindPropertyRelative(nameof(Envelope.holdSustain));

            Rect checkboxLabelRect = checkboxRect;

            EditorGUI.BeginProperty(rect, label, holdSustainProp);
            EditorGUI.LabelField(checkboxLabelRect, label);
            EditorGUI.EndProperty();

            Rect checkboxValueRect = checkboxRect;

            checkboxValueRect.width *= 0.4f;
            checkboxValueRect.x      = rect.xMax - 16;
            EditorGUI.PropertyField(checkboxValueRect, holdSustainProp, GUIContent.none);
        }