public ObjectDuplicationAction(List <GameObject> sourceObjects) { if (sourceObjects != null && sourceObjects.Count != 0) { _sourceParents = GameObjectExtensions.GetParentsFromObjectCollection(sourceObjects); } }
public static List <ObjectSelectionBox> CalculateFromParentsToBottom(IEnumerable <GameObject> selectedObjects) { List <GameObject> parents = GameObjectExtensions.GetParentsFromObjectCollection(selectedObjects); var objectSelectionBoxes = new List <ObjectSelectionBox>(20); foreach (var parent in parents) { Box hierarchyModelSpaceBox = parent.GetHierarchyModelSpaceBox(); if (hierarchyModelSpaceBox.IsValid()) { objectSelectionBoxes.Add(new ObjectSelectionBox(hierarchyModelSpaceBox, parent.transform.localToWorldMatrix)); } } return(objectSelectionBoxes); }
/// <summary> /// When the collection of controlled objects must be transformed by the gizmo, we will /// only apply the transformation to those objects that don't have a parent which resides /// inside the controlled object collection. If we don't do this, results are not very /// pleasing because we would apply the same transformation twice to the children: once /// by transforming the child itself, and a second time, by transforming its parent. This /// function returns a list with all the top parents (objects that don't have a parent /// inside the controlled object collection) that reside in the controlled object collection. /// </summary> /// <remarks> /// If the controlled objects collection hasn't been setup properly, the method will return /// an empty list of objects. /// </remarks> protected List <GameObject> GetParentsFromControlledObjects(bool filterOnlyCanBeManipulated) { // When the controlled game object collection hasn't been setup properly, return an empty list if (ControlledObjects == null) { return(new List <GameObject>()); } if (!filterOnlyCanBeManipulated) { return(GameObjectExtensions.GetParentsFromObjectCollection(ControlledObjects)); } else { List <GameObject> objectsWhichCanBeManipulated = GetControlledObjectsWhichCanBeManipulated(); return(GameObjectExtensions.GetParentsFromObjectCollection(objectsWhichCanBeManipulated)); } }
/// <summary> /// Calculates and returns the object selection boxes for the specified object selection. /// </summary> /// <remarks> /// The method returns only those selection boxes whose model space box is set to /// a valid 'Bounds' instance. /// </remarks> public override List <ObjectSelectionBox> CalculateForObjectSelection(HashSet <GameObject> selectedObjects) { var objectSelectionBoxes = new List <ObjectSelectionBox>(selectedObjects.Count); // We will need to calculate the selection boxes for the hierarchies to which the objects belong, // so we will first retrieve all root objects. var objectRoots = GameObjectExtensions.GetRootObjectsFromObjectCollection(selectedObjects); // Loop through all root objects foreach (GameObject rootObject in objectRoots) { // Retrieve the hierarchy's model space AABB and if it is valid, create a new // object selection box and add it to the output list. Box hierarchyModelSpaceBox = rootObject.GetHierarchyModelSpaceBox(); if (hierarchyModelSpaceBox.IsValid()) { objectSelectionBoxes.Add(new ObjectSelectionBox(hierarchyModelSpaceBox, rootObject.transform.localToWorldMatrix)); } } return(objectSelectionBoxes); }
/// <summary> /// Handles the game objects entered selection shape event. The method returns true if the /// object selection has changed after the event was handled and false otherwise. /// </summary> public override bool Handle(List <GameObject> gameObjects) { EditorObjectSelection editorObjectSelection = EditorObjectSelection.Instance; // We will need to select the entire hierarchy of all objects which were // passed as parameter. We will start by identifying the roots/top parents // of all those objects and store them in a hash set to easily avoid duplicates. var objectRoots = GameObjectExtensions.GetRootObjectsFromObjectCollection(gameObjects); // Now, we need to construct the final object list which will be used to perform the // necessary actions (i.e. select or deselect). We do this by adding the hierarchies // of all root objects that we identified earlier to the same object list. var finalObjectsList = new List <GameObject>(); foreach (GameObject rootObject in objectRoots) { finalObjectsList.AddRange(rootObject.GetAllChildrenIncludingSelf()); } // If multi-object deselection is enabled, we will deselect the game objects which were intersetced by the selection shape if (editorObjectSelection.MultiDeselect) { return(editorObjectSelection.DeselectGameObjectCollection(finalObjectsList)); } else // If append is enabled, we will append the objects to the selection if (editorObjectSelection.AppendOrDeselectOnClick) { return(editorObjectSelection.SelectGameObjectCollection(finalObjectsList)); } // If non of the above, we will clear the selection and make sure that only the specified collection of objects is selected else { return(editorObjectSelection.ClearAndSelectGameObjectCollection(finalObjectsList)); } }