public static void DrawCurve(Color color, AnimationCurve curve1, AnimationCurve curve2, bool activeCurve1, bool activeCurve2, int selectedKey, Rect gridRect, Rect gradRect, bool isIcon = false, float clip = 1.0f) { if (curve2 != null) { int samples = (int)(Screen.height * 0.5f * gridRect.width); Color colorTransp = color; colorTransp.a /= 3f; Vector2 v1 = Vector2.zero; Vector2 v2 = Vector2.zero; Vector2 v1prev; Vector2 v2prev; for (int i = 0; i < samples; ++i) { v1prev = v1; v2prev = v2; float t = (float)i / samples; v1.x = gradRect.xMin + t * (gradRect.xMax - gradRect.xMin); v2.x = v1.x; v1.y = curve1.Evaluate(v1.x); v1 = CurveLines.Convert(v1, gridRect, gradRect); v2.y = curve2.Evaluate(v2.x); v2 = CurveLines.Convert(v2, gridRect, gradRect); if (i > 0) { GL.Begin(GL.QUADS); lineMaterial.color = colorTransp; lineMaterial.SetPass(0); GL.Vertex3(v1prev.x, v1prev.y, mZ); GL.Vertex3(v2prev.x, v2prev.y, mZ); GL.Vertex3(v2.x, v2.y, mZ); GL.Vertex3(v1.x, v1.y, mZ); GL.End(); } } DrawOneCurve(color, curve2, activeCurve2, selectedKey, gridRect, gradRect, isIcon, clip); } DrawOneCurve(color, curve1, activeCurve1, selectedKey, gridRect, gradRect, isIcon, clip); }
static void DrawOneCurve(Color color, AnimationCurve curve, bool activeCurve, int selectedKey, Rect gridRect, Rect gradRect, bool isIcon = false, float clip = 1.0f) { float margin = CurveLines.marginNoDpi * 0.6f; for (int i = 0; i < curve.length; ++i) { Vector2 val = new Vector2(curve[i].time, curve[i].value); val = CurveLines.Convert(val, gridRect, gradRect); //outside of the interval,just draw straigt lines outside from the 1st and last key respectively if (i == 0 && curve.keys[i].time > gradRect.xMin) { GL.Begin(GL.LINES); //GL.Color(color); lineMaterial.color = color; lineMaterial.SetPass(0); GL.Vertex3(gridRect.xMin, val.y, mZ); GL.Vertex3(val.x, val.y, mZ); GL.End(); } if (i == curve.length - 1 && curve.keys[i].time < gradRect.xMax) { GL.Begin(GL.LINES); //GL.Color(color); lineMaterial.color = color; lineMaterial.SetPass(0); GL.Vertex3(val.x, val.y, mZ); GL.Vertex3(gridRect.xMax, val.y, mZ); GL.End(); } if (curve.length > i + 1) { //draw bezier between consecutive keys Vector2 val2 = new Vector2(curve[i + 1].time, curve[i + 1].value); val2 = CurveLines.Convert(val2, gridRect, gradRect); Vector2 c1 = Vector2.zero; Vector2 c2 = Vector2.zero; float tangOut = curve[i].outTangent; float tangIn = curve[i + 1].inTangent; float ratio = (gridRect.height / gridRect.width) * (gradRect.width / gradRect.height); float tangOutScaled = Mathf.Atan(tangOut * ratio); float tangInScaled = Mathf.Atan(tangIn * ratio); if (tangOut != float.PositiveInfinity && tangIn != float.PositiveInfinity) { GetControlPoints(val, val2, tangOut * ratio, tangIn * ratio, out c1, out c2); int samples = (int)(Screen.height * 0.5f * (val2.x - val.x)); DrawBezier(curve, color, samples, val, c1, c2, val2, gridRect, gradRect, clip); } else { DrawConstant(color, val, val2); } if (activeCurve) { if (selectedKey == i) { ContextMenuStruct contextMenu = dictCurvesContextMenus[curve][selectedKey]; if (!contextMenu.auto && (!contextMenu.broken || contextMenu.rightTangent.free)) { Vector2 tangPeak = new Vector2(val.x + CurveLines.tangFixedLength * Mathf.Cos(tangOutScaled), val.y + CurveLines.tangFixedLength * Mathf.Sin(tangOutScaled)); GL.Begin(GL.LINES); lineMaterial.color = Color.gray; lineMaterial.SetPass(0); GL.Vertex3(val.x, val.y, mZ); GL.Vertex3(tangPeak.x, tangPeak.y, mZ); GL.End(); DrawQuad(Color.gray, tangPeak, margin); } } if (selectedKey == i + 1) { ContextMenuStruct contextMenu = dictCurvesContextMenus[curve][selectedKey]; if (!contextMenu.auto && (!contextMenu.broken || contextMenu.leftTangent.free)) { Vector2 tangPeak = new Vector2(val2.x - CurveLines.tangFixedLength * Mathf.Cos(tangInScaled), val2.y - CurveLines.tangFixedLength * Mathf.Sin(tangInScaled)); GL.Begin(GL.LINES); lineMaterial.color = Color.gray; lineMaterial.SetPass(0); GL.Vertex3(val2.x, val2.y, mZ); GL.Vertex3(tangPeak.x, tangPeak.y, mZ); GL.End(); DrawQuad(Color.gray, tangPeak, margin); } } } } if (activeCurve) { if (selectedKey == i) { DrawQuad(lightGray, val, 1.33333f * margin); } } if (!isIcon) { DrawQuad(color, val, margin); } } }