예제 #1
0
        void DrawImpulseShapeCombo(Rect fullRect, SerializedProperty property)
        {
            float floatFieldWidth = EditorGUIUtility.fieldWidth + 2;

            SerializedProperty timeProp = property.FindPropertyRelative(() => m_MyClass.m_ImpulseDuration);

            if (m_TimeText == null)
            {
                m_TimeText      = new GUIContent(" s", timeProp.tooltip);
                m_TimeTextWidth = GUI.skin.label.CalcSize(m_TimeText).x;
            }

            var graphRect = fullRect;

            graphRect.y      += EditorGUIUtility.singleLineHeight + vSpace;
            graphRect.height -= EditorGUIUtility.singleLineHeight + vSpace;

            var indentLevel = EditorGUI.indentLevel;

            Rect r = fullRect; r.height = EditorGUIUtility.singleLineHeight;

            r = EditorGUI.PrefixLabel(r, EditorGUI.BeginProperty(
                                          r, new GUIContent(m_ShapeProperty.displayName, m_ShapeProperty.tooltip), property));
            m_ShapeProperty.isExpanded = EditorGUI.Foldout(r, m_ShapeProperty.isExpanded, GUIContent.none);

            bool isCustom = m_ShapeProperty.intValue == (int)CinemachineImpulseDefinition.ImpulseShapes.Custom;

            r.width -= floatFieldWidth + m_TimeTextWidth;
            if (isCustom)
            {
                r.width -= 2 * r.height;
            }
            EditorGUI.BeginChangeCheck();
            {
                EditorGUI.PropertyField(r, m_ShapeProperty, GUIContent.none);
                if (EditorGUI.EndChangeCheck())
                {
                    InvalidateImpulseGraphSample();
                }
                if (!isCustom && Event.current.type == EventType.Repaint && m_ShapeProperty.isExpanded)
                {
                    DrawImpulseGraph(graphRect, CinemachineImpulseDefinition.GetStandardCurve(
                                         (CinemachineImpulseDefinition.ImpulseShapes)m_ShapeProperty.intValue));
                }
            }
            if (isCustom)
            {
                SerializedProperty curveProp = property.FindPropertyRelative(() => m_MyClass.m_CustomImpulseShape);
                r.x    += r.width;
                r.width = 2 * r.height;
                EditorGUI.BeginChangeCheck();
                EditorGUI.PropertyField(r, curveProp, GUIContent.none);
                if (EditorGUI.EndChangeCheck())
                {
                    curveProp.animationCurveValue = RuntimeUtility.NormalizeCurve(curveProp.animationCurveValue, true, false);
                    curveProp.serializedObject.ApplyModifiedProperties();
                    InvalidateImpulseGraphSample();
                }
                if (Event.current.type == EventType.Repaint && m_ShapeProperty.isExpanded)
                {
                    DrawImpulseGraph(graphRect, curveProp.animationCurveValue);
                }
            }

            // Time
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = m_TimeTextWidth;
            r.x += r.width; r.width = floatFieldWidth + EditorGUIUtility.labelWidth;
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(r, timeProp, m_TimeText);
            if (EditorGUI.EndChangeCheck())
            {
                timeProp.floatValue = Mathf.Max(timeProp.floatValue, 0);
            }
            EditorGUIUtility.labelWidth = oldWidth;

            EditorGUI.indentLevel = indentLevel;
        }
 /// <summary>
 /// Normalize a curve so that each of X and Y axes ranges from 0 to 1
 /// </summary>
 /// <param name="curve">Curve to normalize</param>
 /// <returns>The normalized curve</returns>
 public static AnimationCurve NormalizeCurve(AnimationCurve curve)
 {
     return(RuntimeUtility.NormalizeCurve(curve, true, true));
 }