コード例 #1
0
    private static void drawPath(VectorPath2D path, Color color)
    {
        Vector2[] vertices = path.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 == path.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), path.GetLocalPoint(vertices[i]).ToString());
                }
            }
        }
    }
コード例 #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 path. (-1 if selection failed)</returns>
    public static int TrySelectVertex(this VectorPath2D path, Vector2 position)
    {
        var vertices = path.GetWorldPoints();

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