public bool HasGroup(VertGroup g)
 {
     foreach (var group in Groups)
     {
         if (group.Name == g.Name)
         {
             return(true);
         }
     }
     return(false);
 }
 public VertGroup(VertGroup selectedGroup)
 {
     Name        = selectedGroup.Name;
     VertHandles = new List <GameObject>();
     Color       = selectedGroup.Color;
     foreach (var vertHandle in selectedGroup.VertHandles)
     {
         VertHandles.Add(vertHandle);
         var gizmo = vertHandle.GetComponent <VertHandleGizmo>();
         gizmo.Groups.Add(this);
     }
 }
        private void Update()
        {
            if (Destroy)
            {
                Destroy = false;
                DestroyImmediate(this);
                return;
            }


            if (GroupSelected)
            {
                GroupSelected = false;
                var newGroup = true;
                //for all existing groups
                foreach (var group in Groups)
                {
                    //if this group has the same name as what's in the selected group
                    if (group.Name == SelectedHandles.Name)
                    {
                        //this group already exists
                        newGroup = false;
                        //add any new edges to the group
                        foreach (var vertHandle in SelectedHandles.VertHandles)
                        {
                            if (!group.VertHandles.Contains(vertHandle))
                            {
                                group.VertHandles.Add(vertHandle);
                            }
                            //make the edge know about the group it now belongs to
                            var gizmo = vertHandle.GetComponent <VertHandleGizmo>();
                            if (!gizmo.HasGroup(group))
                            {
                                gizmo.Groups.Add(group);
                            }
                        }
                        //set the group color
                        group.Color = SelectedHandles.Color;
                    }
                }
                if (newGroup)
                {
                    var g = new VertGroup(
                        SelectedHandles); // selectedHandles.name, selectedHandles.edges, selectedHandles.color);
                    Groups.Add(g);
                }
            }

            if (RemoveFromGroup)
            {
                RemoveFromGroup = false;
                foreach (var group in Groups)
                {
                    if (group.Name == SelectedHandles.Name)
                    {
                        foreach (var vertHandle in SelectedHandles.VertHandles)
                        {
                            if (group.VertHandles.Contains(vertHandle))
                            {
                                group.VertHandles.Remove(vertHandle);
                                var gizmo = vertHandle.GetComponent <VertHandleGizmo>();
                                if (gizmo.Groups.Contains(group))
                                {
                                    gizmo.Groups.Remove(group);
                                }
                            }
                        }
                    }
                }
                CleanGroups();
            }

            if (RemoveFromAll)
            {
                RemoveFromAll = false;
                foreach (var group in Groups)
                {
                    foreach (var vertHandle in SelectedHandles.VertHandles)
                    {
                        if (group.VertHandles.Contains(vertHandle))
                        {
                            group.VertHandles.Remove(vertHandle);
                            var gizmo = vertHandle.GetComponent <VertHandleGizmo>();
                            if (gizmo.Groups.Contains(group))
                            {
                                gizmo.Groups.Remove(group);
                            }
                        }
                    }
                }
                CleanGroups();
            }
        }