コード例 #1
0
        private void DrawSpline(DrawMode mode, SplineComponent s)
        {
            int  length   = (int)(s.TotalLength() / SegmentLength);
            bool selected = (mode & DrawMode.Selected) != 0;

            if ((mode & DrawMode.Line) != 0)
            {
                for (int i = 0; i <= length - 1; i++)
                {
                    bool isEven     = i % 2 == 0;
                    var  startPoint = (Vector3)s.Point((float)i / length);
                    var  endPoint   = (Vector3)s.Point((float)(i + 1) / length);
                    var  color      = (selected
                            ? (isEven ? Color.red : Color.green)
                            : Color.white);
                    if ((mode & DrawMode.Darker) != 0)
                    {
                        color *= 0.75f;
                    }
                    Gizmos.color = color;
                    Gizmos.DrawLine(startPoint + OffsetZ,
                                    endPoint + OffsetZ);
                }
            }

            if ((mode & DrawMode.Arrow) != 0)
            {
                Gizmos.color = selected ? Color.cyan : Color.white;
                var center  = s.Point(0.5f);
                var forward = s.Tangent(0.5f);

                Mesh coneMesh = null;
                if (transform.parent.GetComponent <RoadSetup>() != null)
                {
                    coneMesh = transform.parent.GetComponent <RoadSetup>().ConeMesh;
                }

                if (transform.parent.GetComponent <RoadPiece>() != null)
                {
                    coneMesh = transform.parent.GetComponent <RoadPiece>().ConeMesh;
                }

                if (coneMesh != null)
                {
                    Gizmos.DrawMesh(coneMesh, center, Quaternion.LookRotation(forward),
                                    new Vector3(1f, 1f, 2f));
                }
            }
        }