Пример #1
0
    // update
    private void Draw()
    {
        if (pointsList.Count < 1)
        {
            graphics.Clear();
            graphics.Render();
            return;
        }

        graphics.Clear();
        graphics.SetDefaultColor(drawColor0);
        graphics.SetDefaultThickness(thickness);

        Vector3 dir = -Vector3.forward;

        graphics.SetDefaultFaceDir(dir);

        // childを作るかどうかでの処理わけ。childを作らない場合は pointsList を全て描画、作る場合は最新の pointsList のみ描画
        int startIndex = createChildDrawer ? pointsList.Count - 1 : 0;

        for (int i = startIndex; i < pointsList.Count; i++)
        {
            //for (int i = 0; i < pointsList.Count; i++) {
            List <Vector3> points         = pointsList[i];
            float[]        thicknessArray = new float[points.Count];
            Color[]        colorArray     = new Color[points.Count];
            for (int j = 0; j < thicknessArray.Length; j++)
            {
                if (j == 0)
                {
                    thicknessArray[j] = thicknessMin;
                    colorArray[j]     = drawColor0;
                }
                else
                {
                    float dist = Vector3.Distance(points[j - 1], points[j]);
                    //thicknessArray[j] = (1-(dist / 40f)) * thickness + thickness;
                    float t = 1 - Mathf.Clamp01(dist / distLimit);
                    colorArray[j] = Color.Lerp(drawColor0, drawColor1, t);
                    //thicknessArray[j] = thickness;
                    //thicknessArray[j] = t * thickness + thicknessMin;
                    thicknessArray[j] = ((t * thickness + thicknessMin) + thicknessArray[j - 1]) * 0.5f; // avg
                }
            }
            //
            if (useCatmull)
            {
                //graphics.DrawSpline(points.ToArray(), thicknessArray, colorArray);
                graphics.DrawQuadraticCurve(points.ToArray(), thicknessArray, colorArray);
            }
            else
            {
                graphics.DrawLine(points.ToArray(), thicknessArray);
            }
        }
        graphics.Render();
    }