Example #1
0
        public void RemoveVertex(int index)
        {
            Debug.Assert(spriteMeshData != null);

            //We need to delete the edges that reference the index
            List <Edge> edgesWithIndex;

            if (FindEdgesContainsIndex(index, out edgesWithIndex))
            {
                //If there are 2 edges referencing the same index we are removing, we can create a new one that connects the endpoints ("Unsplit").
                if (edgesWithIndex.Count == 2)
                {
                    Edge first  = edgesWithIndex[0];
                    Edge second = edgesWithIndex[1];

                    int index1 = first.index1 != index ? first.index1 : first.index2;
                    int index2 = second.index1 != index ? second.index1 : second.index2;

                    CreateEdge(index1, index2);
                }

                //remove found edges
                for (int i = 0; i < edgesWithIndex.Count; i++)
                {
                    RemoveEdge(edgesWithIndex[i]);
                }
            }

            //Fix indices in edges greater than the one we are removing
            for (int i = 0; i < spriteMeshData.edges.Count; i++)
            {
                Edge edge = spriteMeshData.edges[i];

                if (edge.index1 > index)
                {
                    edge.index1--;
                }
                if (edge.index2 > index)
                {
                    edge.index2--;
                }

                spriteMeshData.edges[i] = edge;
            }

            spriteMeshData.RemoveVertex(index);
        }