public static void AlignSelectionToAxis(Axis axis) { int axisIndex = (int)axis; List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); List <GameObject> selectedParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(allSelectedObjects); if (selectedParents.Count == 0) { return; } float average = 0.0f; foreach (var parent in selectedParents) { average += parent.transform.position[axisIndex]; } average /= selectedParents.Count; GameObjectExtensions.RecordObjectTransformsForUndo(selectedParents); foreach (var parent in selectedParents) { Transform parentTransform = parent.transform; Vector3 alignedPosition = parentTransform.position; alignedPosition[axisIndex] = average; parentTransform.position = alignedPosition; } }
public void Begin() { if (_state != State.Inactive) { return; } _state = State.SelectPivot; _selectedParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(ObjectSelection.Get().GetAllSelectedGameObjects()); }
public void CombineSelectedObjects(List <GameObject> selectedObjects, List <GameObject> ignoreObjects) { if (_combineSettings == null || selectedObjects == null) { return; } if (selectedObjects.Count == 0) { EditorUtility.DisplayDialog("No Selected Objects", "The mesh combine process can not start because there are no objects currently selected.", "Ok"); return; } List <GameObject> allMeshObjects = new List <GameObject>(selectedObjects.Count); foreach (var selectedObject in selectedObjects) { if (selectedObject.HasMeshFilterWithValidMesh()) { allMeshObjects.Add(selectedObject); } } if (ignoreObjects != null && ignoreObjects.Count != 0) { allMeshObjects.RemoveAll(item => ignoreObjects.Contains(item)); } List <MeshCombineMaterial> meshCombineMaterials = GetMeshCombineMaterials(allMeshObjects, null); if (meshCombineMaterials.Count == 0) { EditorUtility.DisplayDialog("No Combinable Objects", "The current selection does not contain any objects which can be combined. Please check the following: \n\r" + "-the selection must contain mesh objects; \n\r " + "-check the \'Combine static/dynamic meshes\' toggles to ensure that the objects can actually be combined; \n\r" + "-if the objects belong to a hierarchy, make sure to unhceck the \'Ignore objects in hierarchies\' toggle.", "Ok"); return; } Combine(meshCombineMaterials, _combineSettings.SelectionCombineDestinationParent); if (_combineSettings.SelCombineMode == MeshCombineSettings.CombineMode.Replace) { List <GameObject> parents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(selectedObjects); foreach (var parent in parents) { UndoEx.DestroyObjectImmediate(parent); } } EditorUtility.DisplayDialog("Done!", "Mesh objects combined successfully!", "Ok"); }
public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint) { if (CanTransformObjects()) { Vector3 newScaleAccumulatedByGizmoInteraction = Handles.ScaleHandle(_scaleAccumulatedByGizmoInteraction, _worldPosition, _worldRotation, HandleUtility.GetHandleSize(_worldPosition)); if (newScaleAccumulatedByGizmoInteraction != _scaleAccumulatedByGizmoInteraction) { GameObjectExtensions.RecordObjectTransformsForUndo(_gameObjectsWhichCanBeTransformed); List <GameObject> topParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(_gameObjectsWhichCanBeTransformed); Vector3 scaleFactor = CalculateScaleFactorUsedToScaleObjects(newScaleAccumulatedByGizmoInteraction); ScaleObjectsBySpecifiedPivotPoint(transformPivotPoint, scaleFactor, topParents); _scaleAccumulatedByGizmoInteraction = newScaleAccumulatedByGizmoInteraction; GizmoTransformedObjectsMessage.SendToInterestedListeners(this); } } }
public void RenderGizmos() { SelectionShape.RenderGizmos(); _selectionSnapSession.RenderGizmos(); _selectionGrabSession.RenderGizmos(); IObjectSelectionRenderer objectSelectionRenderer = ObjectSelectionRendererFactory.Create(); objectSelectionRenderer.Render(GetAllSelectedGameObjects()); if (Mirror.IsActive) { Mirror.RenderGizmos(); List <GameObject> topLevelParentsInSelection = GameObjectExtensions.GetTopParentsFromGameObjectCollection(_selectedObjects.HashSet); Mirror.RenderMirroredEntityOrientedBoxes(GameObjectExtensions.GetHierarchyWorldOrientedBoxes(topLevelParentsInSelection)); } }
public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint) { if (CanTransformObjects()) { Vector3 newGizmoWorldPosition = Handles.PositionHandle(_worldPosition, _worldRotation); if (newGizmoWorldPosition != _worldPosition) { GameObjectExtensions.RecordObjectTransformsForUndo(_gameObjectsWhichCanBeTransformed); List <GameObject> topParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(_gameObjectsWhichCanBeTransformed); MoveObjects(newGizmoWorldPosition, topParents); UndoEx.RecordForToolAction(this); _worldPosition = newGizmoWorldPosition; GizmoTransformedObjectsMessage.SendToInterestedListeners(this); } } }
public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint) { if (CanTransformObjects()) { Quaternion newWorldRotationAccumulatedByGizmoInteraction = Handles.RotationHandle(_worldRotation, _worldPosition); if (newWorldRotationAccumulatedByGizmoInteraction.eulerAngles != _worldRotation.eulerAngles) { GameObjectExtensions.RecordObjectTransformsForUndo(_gameObjectsWhichCanBeTransformed); List <GameObject> topParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(_gameObjectsWhichCanBeTransformed); Quaternion rotationAmount = CalculateRotationAmount(newWorldRotationAccumulatedByGizmoInteraction); RotateObjectsAroundSpecifiedPivotPoint(transformPivotPoint, rotationAmount, topParents); UndoEx.RecordForToolAction(this); _worldRotation = newWorldRotationAccumulatedByGizmoInteraction; GizmoTransformedObjectsMessage.SendToInterestedListeners(this); } } }
public void CombineSelectedObjects(List <GameObject> selectedObjects, List <GameObject> ignoreObjects) { if (_combineSettings == null || selectedObjects == null || selectedObjects.Count == 0) { return; } List <GameObject> allMeshObjects = new List <GameObject>(selectedObjects.Count); foreach (var selectedObject in selectedObjects) { if (selectedObject.HasMeshFilterWithValidMesh()) { allMeshObjects.Add(selectedObject); } } if (ignoreObjects != null && ignoreObjects.Count != 0) { allMeshObjects.RemoveAll(item => ignoreObjects.Contains(item)); } List <MeshCombineMaterial> meshCombineMaterials = GetMeshCombineMaterials(allMeshObjects, null); if (meshCombineMaterials.Count == 0) { return; } Combine(meshCombineMaterials, _combineSettings.SelectionCombineDestinationParent); if (_combineSettings.SelCombineMode == MeshCombineSettings.CombineMode.Replace) { List <GameObject> parents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(selectedObjects); foreach (var parent in parents) { UndoEx.DestroyObjectImmediate(parent); } } }
public static void DuplicateSelection() { if (ObjectSelection.Get().NumberOfSelectedObjects == 0) { return; } ObjectSelection objectSelection = ObjectSelection.Get(); List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects(); List <GameObject> selectedParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(allSelectedObjects); var clonedObjects = new List <GameObject>(); foreach (GameObject parent in selectedParents) { GameObject prefab = parent.GetSourcePrefab(); Transform parentTransform = parent.transform; if (prefab == null) { GameObject clonedParent = parent.CloneAsWorkingObject(parentTransform.parent); //clonedParent.transform.parent = parent.transform.parent; clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); } else { GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale); clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); } } if (clonedObjects.Count != 0) { objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(clonedObjects); objectSelection.ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated(); } }
public void HandleKeyboardButtonDownEvent(Event e) { if (AllShortcutCombos.Instance.GrabSelection.IsActive() && NumberOfSelectedObjects != 0) { if (_selectionGrabSession.IsActive) { _selectionGrabSession.End(); } else { _selectionGrabSession.Settings = SelectionGrabSettings; _selectionGrabSession.Begin(new List <GameObject>(_selectedObjects.HashSet)); } } if (_selectionGrabSession.IsActive || _selectionSnapSession.IsActive) { return; } // Note: Don't disable this event if it's CTRL or CMD because transform // handle snapping will no longer work. if (e.keyCode != KeyCode.LeftControl && e.keyCode != KeyCode.LeftCommand && e.keyCode != KeyCode.RightControl && e.keyCode != KeyCode.RightCommand) { e.DisableInSceneView(); } if (Mirror.IsInteractionSessionActive) { Mirror.HandleKeyboardButtonDownEvent(e); return; } if (Mirror.IsActive && AllShortcutCombos.Instance.MirrorSelectedObjects.IsActive()) { List <GameObject> topParentsInSelectedObjects = GameObjectExtensions.GetTopParentsFromGameObjectCollection(_selectedObjects.HashSet); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(Mirror.MirrorGameObjectHierarchies(topParentsInSelectedObjects), ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.MirroredSelection); return; } if (AllShortcutCombos.Instance.DeleteSelectedObjects.IsActive()) { UndoEx.RecordForToolAction(this); ObjectActions.EraseAllSelectedGameObjects(); } else if (AllShortcutCombos.Instance.SelectAllObjectsWithSamePrefabAsCurrentSelection.IsActive()) { UndoEx.RecordForToolAction(this); ObjectSelectionActions.SelectAllObjectsWithSamePrefabAsCurrentSelection(); _objectSelectionTransformGizmoSystem.OnObjectSelectionUpdated(); } else if (AllShortcutCombos.Instance.ToggleGizmosOnOff.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionTransformGizmoSystem); _objectSelectionTransformGizmoSystem.AreGizmosActive = !_objectSelectionTransformGizmoSystem.AreGizmosActive; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ActivateMoveGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionTransformGizmoSystem); _objectSelectionTransformGizmoSystem.ActiveGizmoType = TransformGizmoType.Move; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ActivateRotationGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionTransformGizmoSystem); _objectSelectionTransformGizmoSystem.ActiveGizmoType = TransformGizmoType.Rotate; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ActivateScaleGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionTransformGizmoSystem); _objectSelectionTransformGizmoSystem.ActiveGizmoType = TransformGizmoType.Scale; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ProjectSelectedObjects.IsActive()) { ProjectSelectionOnProjectionSurface(); } else if (AllShortcutCombos.Instance.SnapSelection.IsActive()) { _selectionSnapSession.Begin(); } }