/// <summary> /// Reparents and gameobject within the bounds of target object. /// </summary> /// <param name="targetObject">The target object.</param> /// <param name="target">The target.</param> private void ReparentToBoundsContent(GameObject targetObject, Bounds target) { using (new UndoScope("Reparent Objects to comment")) { var allObjects = FindObjectsOfType <GameObject>().Select(x => x.transform).Where( x => { if (x.GetComponent < BlockoutSection >()) { return(false); } if (x.parent == null ) { return(false); } if (x.parent == targetObject) { return(false); } if (x .parent .GetComponent < BlockoutSection >()) { return(true); } return(false); } ).ToArray(); if (!targetObject.GetComponent <BlockoutSection>()) { targetObject.AddComponent <BlockoutSection>().Section = SectionID.Root; } BlockoutStaticFunctions.CreateBlockoutSubHeirachyWithRoot(targetObject.transform, targetObject.name + "_"); Undo.RecordObjects(allObjects, "Reparent Objects"); for (var i = 0; i < allObjects.Length; ++i) { Bounds colliderBounds; if (allObjects[i].GetComponent <Collider>()) { colliderBounds = allObjects[i].GetComponent <Collider>().bounds; } else if (allObjects[i].GetComponent <Renderer>()) { colliderBounds = allObjects[i].GetComponent <Renderer>().bounds; } else { continue; } if (target.Contains(colliderBounds.max) && target.Contains(colliderBounds.min)) { var section = allObjects[i].transform.parent.GetComponent <BlockoutSection>(); if (section) { BlockoutStaticFunctions.ReparentObjectToTargetRoot(allObjects[i].transform, targetObject.transform); } } } BlockoutStaticFunctions.TrimTargetBlockoutHierarchy(targetObject); } }