public static int Remove(XmlSpawner spawner, string toRemove) { List <XmlSpawner.SpawnObject> remove = new List <XmlSpawner.SpawnObject>(); List <XmlSpawner.SpawnObject> objects = spawner.SpawnObjects.ToList(); foreach (var obj in objects) { if (obj == null || obj.TypeName == null) { continue; } string typeName = obj.TypeName.ToLower(); string lookingFor = toRemove.ToLower(); if (typeName != null && typeName.IndexOf(lookingFor) >= 0) { remove.Add(obj); } } int count = remove.Count; foreach (var obj in remove) { spawner.RemoveSpawnObject(obj); } ColUtility.Free(remove); return(count); }