public void RemoveGroup(MyBlockGroup group) { bool removed = false; if (!BlockGroups.Contains(group)) // if you delete from terminal group matches and you delete whole group { for (int index = 0; index < BlockGroups.Count; index++) { var g = BlockGroups[index]; if (g.Name.CompareTo(group.Name) == 0) { for (int i = 0; i < g.Blocks.Count; i++) { var b = g.Blocks[i]; if (b.CubeGrid == group.CubeGrid) //remove only blocks of that grid from group { g.Blocks.Remove(b); i--; } } if (g.Blocks.Count == 0) { group = g; //group to remove } else { removed = true; } break; } } } if (!removed) { BlockGroups.Remove(group); } if (GroupRemoved != null && group.CubeGrid == null) { GroupRemoved(group); } }
public void RemoveGroup(MyBlockGroup group) { bool removed = false; if (!BlockGroups.Contains(group)) // if you delete from terminal group matches and you delete whole group { foreach (var g in BlockGroups) //removing group from grid side (grid disconnected, or last block from that grid group removed) { if (g.Name.CompareTo(group.Name) == 0) { for (int i = 0; i < g.Blocks.Count; i++) { var b = g.Blocks[i]; if (b.CubeGrid == group.CubeGrid) //remove only blocks of that grid from group { g.Blocks.Remove(b); i--; } } if (g.Blocks.Count == 0) { group = g; //group to remove } else { removed = true; } break; } } } if (!removed) { BlockGroups.Remove(group); } if (GroupRemoved != null) { GroupRemoved(group); } }