public void CreateCurve(IStorableAnimationCurve storable, UICurveLineColors colors, float thickness) { var line = new CurveLine(storable, colors); line.thickness = thickness; _lines.Add(line); _scrubberPositions.Add(line, line.curve.keys.First().time); _storableToLineMap.Add(storable, line); SetVerticesDirty(); }
public CurveEditorPoint(CurveLine parent, UICurveLineColors colors = null) { this.parent = parent; _colors = colors ?? new UICurveLineColors(); pointColor = _colors.pointColor; inHandleColor = _colors.inHandleColor; outHandleColor = _colors.outHandleColor; lineColor = _colors.handleLineColor; }
private void PopulateGrid(VertexHelper vh, Rect viewBounds, CurveLine line) { if (line == null) { return; } var viewMin = viewBounds.min; var viewMax = viewBounds.max; var cellSize = GetGridCellSize(line, viewBounds); var minX = Mathf.Floor(viewMin.x / cellSize.x) * cellSize.x; var maxX = Mathf.Ceil(viewMax.x / cellSize.x) * cellSize.x; var minY = Mathf.Floor(viewMin.y / cellSize.y) * cellSize.y; var maxY = Mathf.Ceil(viewMax.y / cellSize.y) * cellSize.y; if ((maxX - minX) / cellSize.x < 100) { for (var x = minX; x <= maxX; x += cellSize.x) { vh.AddLine(new Vector2(x, viewMin.y), new Vector2(x, viewMax.y), 0.01f, _gridColor, _viewMatrix); } } if ((maxY - minY) / cellSize.x < 100) { for (var y = minY; y <= maxY; y += cellSize.y) { vh.AddLine(new Vector2(viewMin.x, y), new Vector2(viewMax.x, y), 0.01f, _gridColor, _viewMatrix); } } if (viewMin.y < 0 && viewMax.y > 0) { vh.AddLine(new Vector2(viewMin.x, 0), new Vector2(viewMax.x, 0), 0.04f, _girdAxisColor, _viewMatrix); } if (viewMin.x < 0 && viewMax.x > 0) { vh.AddLine(new Vector2(0, viewMin.y), new Vector2(0, viewMax.y), 0.04f, _girdAxisColor, _viewMatrix); } }
private Vector2 GetGridCellSize(CurveLine line, Rect viewBouns) { var viewMin = line.drawScale.inverse.Scale(viewBouns.min); var viewMax = line.drawScale.inverse.Scale(viewBouns.max); var stepCount = 10; var roughStep = (viewMax - viewMin) / (stepCount - 1); var stepPower = new Vector2( Mathf.Pow(2, -Mathf.Floor(Mathf.Log(Mathf.Abs(roughStep.x), 2))), Mathf.Pow(2, -Mathf.Floor(Mathf.Log(Mathf.Abs(roughStep.y), 2))) ); var normalizedStep = roughStep * stepPower; var step = new Vector2( Mathf.NextPowerOfTwo(Mathf.CeilToInt(normalizedStep.x)), Mathf.NextPowerOfTwo(Mathf.CeilToInt(normalizedStep.y)) ); return(line.drawScale.Scale(step / stepPower)); }