UnityEditor.ParticleSystemClipboard.ClampCurve C# (CSharp) Method

ClampCurve() private static method

private static ClampCurve ( UnityEditor.SerializedProperty animCurveProperty, Rect curveRanges ) : void
animCurveProperty UnityEditor.SerializedProperty
curveRanges UnityEngine.Rect
return void
        private static void ClampCurve(SerializedProperty animCurveProperty, Rect curveRanges)
        {
            AnimationCurve animationCurveValue = animCurveProperty.animationCurveValue;
            Keyframe[] keys = animationCurveValue.keys;
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i].time = Mathf.Clamp(keys[i].time, curveRanges.xMin, curveRanges.xMax);
                keys[i].value = Mathf.Clamp(keys[i].value, curveRanges.yMin, curveRanges.yMax);
            }
            animationCurveValue.keys = keys;
            animCurveProperty.animationCurveValue = animationCurveValue;
        }

Usage Example

 public static void PasteAnimationCurves(SerializedProperty animCurveProperty, SerializedProperty animCurveProperty2, SerializedProperty scalarProperty, Rect curveRanges, ParticleSystemCurveEditor particleSystemCurveEditor)
 {
     if (animCurveProperty != null && ParticleSystemClipboard.m_AnimationCurve1 != null)
     {
         animCurveProperty.animationCurveValue = ParticleSystemClipboard.m_AnimationCurve1;
         ParticleSystemClipboard.ClampCurve(animCurveProperty, curveRanges);
     }
     if (animCurveProperty2 != null && ParticleSystemClipboard.m_AnimationCurve2 != null)
     {
         animCurveProperty2.animationCurveValue = ParticleSystemClipboard.m_AnimationCurve2;
         ParticleSystemClipboard.ClampCurve(animCurveProperty2, curveRanges);
     }
     if (scalarProperty != null)
     {
         scalarProperty.floatValue = ParticleSystemClipboard.m_AnimationCurveScalar;
     }
     if (particleSystemCurveEditor != null)
     {
         particleSystemCurveEditor.Refresh();
     }
 }