コード例 #1
0
    private void DrawOneEdge(Edge edge, bool drawWithVoronoiColor = false, int offsetZ = 0)
    {
        bool drawNormale = false;

        GameObject seg;

        if (drawWithVoronoiColor)
        {
            seg = Instantiate(voronoiSegment);
        }
        else
        {
            seg = Instantiate(segment);
        }

        goInScene.Add(seg);

        Vector3 pos = (edge.p1.GetPosition() + edge.p2.GetPosition()) / 2;

        pos.z += offsetZ;

        seg.transform.rotation = Quaternion.LookRotation(edge.p1.GetPosition() - edge.p2.GetPosition(), Vector3.up);
        seg.transform.Rotate(Vector3.right * 90);

        Vector3 localScale = Vector3.one;

        localScale.y             = Vector3.Distance(edge.p1.GetPosition(), edge.p2.GetPosition()) / 2;
        seg.transform.localScale = localScale;

        seg.transform.position = pos;

        if (drawNormale)
        {
            Vector3 normale = edge.GetNormal();
            seg = Instantiate(segment);

            pos = (edge.p1.GetPosition() + edge.p2.GetPosition()) / 2;
            seg.transform.rotation = Quaternion.LookRotation(normale, Vector3.up);
            seg.transform.Rotate(Vector3.right * 90);

            pos                     += normale;
            localScale               = Vector3.one;
            localScale.y             = 2;
            seg.transform.localScale = localScale;

            seg.transform.position = pos;
        }
    }