Exemplo n.º 1
0
    private static void drawEdge(EdgeCollider2D edge, Color color)
    {
        Vector2[] vertices = edge.GetWorldPoints();
        if (vertices == null)
        {
            return;
        }

        for (int i = 0; i < vertices.Length; i++)
        {
            int ii = (i + 1) % vertices.Length;
            // Draw edge
            if (ii != 0)
            {
                Gizmos.color = color;
                Gizmos.DrawLine(vertices[i], vertices[ii]);
            }

            // Draw vertex
            if (Selection.activeGameObject == edge.gameObject)
            {
                Gizmos.color = ColorPalletReader.GetVertexColor(ColorStates.PATH);
                if (i == _selectedVertex)
                {
                    Gizmos.color = ColorPalletReader.GetVertexColor(ColorStates.SELECTED);
                }
                Gizmos.DrawSphere(vertices[i], BrushSettingsWindow.VertexSize);
                if (BrushSettingsWindow.ShowVertexInfo == true)
                {
                    Handles.Label(vertices[i] + new Vector2(0.1f, 0.4f), edge.GetLocalPoint(vertices[i]).ToString());
                }
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Tries to select a vertex at the given position. Takes
    /// specified selection radius into account. Returns the
    /// index of the vertex within the given path. Returns
    /// -1 if no vertex could be selected.
    /// </summary>
    /// <param name="position">The position at which the vertex should be selected</param>
    /// <returns>Returns the index of the selected vertex within the edge. (-1 if selection failed)</returns>
    public static int TrySelectVertex(this EdgeCollider2D edge, Vector2 position)
    {
        var vertices = edge.GetWorldPoints();

        for (int i = 0; i < vertices.Length; i++)
        {
            var vertex = vertices[i];
            if ((vertex - position).magnitude <= BrushSettingsWindow.VertexSize)
            {
                return(i);
            }
        }
        return(-1);
    }