//Removes objects from the list, that do not share at lease one common component with brokenPrefab private void FindSimilarObjectsByComponents(List <GameObject> objectsToBeFiltered) { if (componentIntersection.Count == 0) { CompareObjects(); } var currentComponents = componentIntersection.Where(c => c.IsActivated).Select(c => c.ComponentType); var objectsToRemove = new List <GameObject>(); foreach (GameObject gameObject in objectsToBeFiltered) { var sceneObjectComponents = GameObjectHelper.GetComponentsInAllChildren <Component>(gameObject).Select(c => c.GetType()).ToList(); var intersectingComponentsAmount = sceneObjectComponents.Join(currentComponents, a => a, b => b, (a, b) => a).Count(); if (intersectingComponentsAmount == 0) { objectsToRemove.Add(gameObject); } } objectsToBeFiltered.RemoveAll(o => objectsToRemove.Contains(o)); }
//Creates a lookup table with the old objects id being the key and the new instance being the value private void MakeHistory(GameObject oldObject, GameObject newObject) { var idHierarchy = GameObjectHelper.GetAllChildrenOf(oldObject, true).Select(go => go.GetInstanceID()).ToList(); idHierarchy.ForEach(id => replacementHistory.Add(id, newObject)); }