public static List <GameObject> ReplaceSelectedObjectsPrefabOnMouseClick() { MouseCursorRayHit cursorRayHit = ObjectSelection.Get().GetObjectPickedByCursor(); if (cursorRayHit.WasAnObjectHit && !ObjectSelection.Get().IsGameObjectSelected(cursorRayHit.ClosestObjectRayHit.HitObject)) { GameObject hitObject = cursorRayHit.ClosestObjectRayHit.HitObject; hitObject = Octave3DWorldBuilder.ActiveInstance.GetRoot(hitObject); if (hitObject == null) { return(new List <GameObject>()); } GameObject newPrefabForSelectedObjects = hitObject.GetSourcePrefab(); if (newPrefabForSelectedObjects == null) { return(new List <GameObject>()); } List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects); List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, newPrefabForSelectedObjects); newObjects.RemoveAll(item => item == null); return(newObjects); } return(new List <GameObject>()); }
private void RenderEraseAllLayersButton() { if (GUILayout.Button(GetContentForEraseAllLayersButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth * _actionButtonScale))) { UndoEx.RecordForToolAction(ObjectSelection.Get()); ObjectActions.EraseGameObjectsInAllLayers(); } }
private void RenderMakeSelectionDynamicButton() { if (GUILayout.Button(GetContentForMakeSelectionDynamicButton(), GUILayout.Width(110.0f))) { List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); UndoEx.RecordForToolAction(allSelectedObjects); ObjectActions.MakeObjectsDynamic(allSelectedObjects); } }
private void RenderMakeActiveGroupDynamicButton() { if (GUILayout.Button(GetContentForMakeActiveGroupDynamicButton())) { List <GameObject> allObjectsInActivegroup = _database.ActiveGroup.GroupObject.GetAllChildrenIncludingSelf(); UndoEx.RecordForToolAction(allObjectsInActivegroup); ObjectActions.MakeObjectsDynamic(allObjectsInActivegroup); } }
private void RenderMakeActiveGroupStaticButton() { if (GUILayout.Button(GetContentForMakeActiveGroupStaticButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth))) { List <GameObject> allObjectsInActivegroup = _database.ActiveGroup.GroupObject.GetAllChildrenIncludingSelf(); UndoEx.RecordForToolAction(allObjectsInActivegroup); ObjectActions.MakeObjectsStatic(allObjectsInActivegroup); } }
public static List <GameObject> ReplaceSelectedObjectsWithPrefab(GameObject prefab) { List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects); List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, prefab); newObjects.RemoveAll(item => item == null); return(newObjects); }
public static List <GameObject> ReplaceSelectedObjectsPrefabOnMouseClick() { MouseCursorRayHit cursorRayHit = ObjectSelection.Get().GetObjectPickedByCursor(); if (cursorRayHit.WasAnObjectHit && !ObjectSelection.Get().IsGameObjectSelected(cursorRayHit.ClosestObjectRayHit.HitObject)) { GameObject hitObject = cursorRayHit.ClosestObjectRayHit.HitObject; hitObject = Octave3DWorldBuilder.ActiveInstance.GetRoot(hitObject); if (hitObject == null) { return(new List <GameObject>()); } GameObject newPrefabForSelectedObjects = hitObject.GetSourcePrefab(); if (newPrefabForSelectedObjects == null) { List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects); List <GameObject> selectedRoots = Octave3DWorldBuilder.ActiveInstance.GetRoots(allSelectedObjects); var newObjects = new List <GameObject>(); foreach (var root in selectedRoots) { Transform rootTransform = root.transform; GameObject newObject = GameObjectExtensions.CloneAsWorkingObject(hitObject, hitObject.transform.parent, true); if (newObject != null) { Transform objectTransform = newObject.transform; objectTransform.position = rootTransform.position; objectTransform.rotation = rootTransform.rotation; objectTransform.SetWorldScale(rootTransform.lossyScale); newObject.SetSelectedHierarchyWireframeHidden(ObjectPlacementSettings.Get().HideWireframeWhenPlacingObjects); UndoEx.DestroyObjectImmediate(root); newObjects.Add(newObject); } } return(newObjects); } else { List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects); List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, newPrefabForSelectedObjects); newObjects.RemoveAll(item => item == null); return(newObjects); } } return(new List <GameObject>()); }
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(); } }
public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint) { Box targetWorldAABB = Box.FromObjectWorldAABB(_targetObjects); //Color[] axesColors = new Color[] { Handles.xAxisColor, Handles.xAxisColor, Handles.yAxisColor, Handles.yAxisColor, Handles.zAxisColor, Handles.zAxisColor }; //Vector3[] axesDirs = new Vector3[] { Vector3.right, -Vector3.right, Vector3.up, -Vector3.up, Vector3.forward, -Vector3.forward }; //float[] snapValues = new float[] { targetWorldAABB.Size.x, targetWorldAABB.Size.x, targetWorldAABB.Size.y, targetWorldAABB.Size.y, targetWorldAABB.Size.z, targetWorldAABB.Size.z }; Color[] axesColors = new Color[] { Handles.xAxisColor, Handles.yAxisColor, Handles.zAxisColor }; Vector3[] axesDirs = new Vector3[] { Vector3.right, Vector3.up, Vector3.forward }; float[] snapValues = new float[] { targetWorldAABB.Size.x *_snapSteps[0], targetWorldAABB.Size.y *_snapSteps[1], targetWorldAABB.Size.z *_snapSteps[2] }; Vector3 oldPosition = WorldPosition; for (int axisIndex = 0; axisIndex < 3; ++axisIndex) { Handles.color = axesColors[axisIndex]; Vector3 newGizmoPosition = Handles.Slider(oldPosition, axesDirs[axisIndex], HandleUtility.GetHandleSize(oldPosition), Handles.ArrowHandleCap, snapValues[axisIndex]); if (newGizmoPosition != oldPosition) { Vector3 moveOffset = (newGizmoPosition - oldPosition); WorldPosition = newGizmoPosition; oldPosition = newGizmoPosition; if (Event.current.control) { float absNumGroups = Mathf.Abs(moveOffset[axisIndex] / snapValues[axisIndex]); float absFractional = absNumGroups - (int)absNumGroups; int numCloneGroups = Mathf.FloorToInt(absNumGroups); if (Mathf.Abs(absFractional - 1.0f) < 1e-4f) { ++numCloneGroups; } for (int cloneGroupIndex = 0; cloneGroupIndex < numCloneGroups; ++cloneGroupIndex) { var clonedRoots = Octave3DWorldBuilder.ActiveInstance.GetRoots(ObjectActions.Duplicate(_targetObjects)); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(clonedRoots, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(ObjectSelection.Get().Mirror.MirrorGameObjectHierarchies(clonedRoots), ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection); if (cloneGroupIndex != 0) { Vector3 offset = axesDirs[axisIndex] * snapValues[axisIndex] * cloneGroupIndex *Mathf.Sign(moveOffset[axisIndex]); foreach (var root in clonedRoots) { root.transform.position += offset; } } } } GameObjectExtensions.RecordObjectTransformsForUndo(_targetObjects); var targetParents = GameObjectExtensions.GetParents(_targetObjects); foreach (var parent in targetParents) { parent.transform.position += moveOffset; } } } Handles.BeginGUI(); GUI.BeginGroup(new Rect(0.0f, -15.0f, 200.0f, 200.0f)); var content = new GUIContent(); string[] snapStepLabels = new string[] { "Snap step X", "Snap step Y", "Snap step Z" }; for (int axisIndex = 0; axisIndex < 3; ++axisIndex) { EditorGUILayout.BeginHorizontal(); content.text = snapStepLabels[axisIndex]; EditorGUILayout.LabelField(content, GUILayout.Width(80.0f)); int newInt = EditorGUILayout.IntField("", _snapSteps[axisIndex], GUILayout.Width(50.0f)); if (newInt != _snapSteps[axisIndex]) { UndoEx.RecordForToolAction(this); SetSnapStep(axisIndex, newInt); } EditorGUILayout.EndHorizontal(); } GUI.EndGroup(); Handles.EndGUI(); }
public void HandleKeyboardButtonDownEvent(Event e) { if (AllShortcutCombos.Instance.ActivateObjectVertexSnapSession_Placement.IsActive() && !_object2ObjectSnapSession.IsActive && !_selectionGrabSession.IsActive && !SelectionShape.IsVisible()) { e.DisableInSceneView(); _objectVertexSnapSession.Begin(GetAllSelectedGameObjects()); return; } if (!_object2ObjectSnapSession.IsActive) { 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) { if (AllShortcutCombos.Instance.ToggleSelectionObject2ObjectSnap.IsActive() && NumberOfSelectedObjects != 0) { if (_object2ObjectSnapSession.IsActive) { _object2ObjectSnapSession.End(); } else { _object2ObjectSnapSession.Begin(); } } } if (_object2ObjectSnapSession.IsActive) { if (AllShortcutCombos.Instance.SelectionRotateWorldX.IsActive()) { Rotate(Settings.XRotationStep, Vector3.right); } else if (AllShortcutCombos.Instance.SelectionRotateWorldY.IsActive()) { Rotate(Settings.YRotationStep, Vector3.up); } else if (AllShortcutCombos.Instance.SelectionRotateWorldZ.IsActive()) { Rotate(Settings.ZRotationStep, Vector3.forward); } else if (AllShortcutCombos.Instance.SetRotationToIdentity.IsActive()) { SetWorldRotation(Quaternion.identity); } return; } if (_selectionGrabSession.IsActive || _selectionGridSnapSession.IsActive || _object2ObjectSnapSession.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> selectedRoots = Octave3DWorldBuilder.ActiveInstance.GetRoots(GetAllSelectedGameObjects()); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(Mirror.MirrorGameObjectHierarchies(selectedRoots), ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection); return; } if (AllShortcutCombos.Instance.DeleteSelectedObjects.IsActive()) { UndoEx.RecordForToolAction(this); ObjectActions.EraseAllSelectedGameObjects(); } else if (AllShortcutCombos.Instance.SelectAllObjectsWithSamePrefabAsCurrentSelection.IsActive()) { UndoEx.RecordForToolAction(this); ObjectSelectionActions.SelectAllObjectsWithSamePrefabAsCurrentSelection(); _objectSelectionGizmos.OnObjectSelectionUpdated(); } else if (AllShortcutCombos.Instance.ActivateMoveGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionGizmos); _objectSelectionGizmos.ActiveGizmoType = GizmoType.Move; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ActivateRotationGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionGizmos); _objectSelectionGizmos.ActiveGizmoType = GizmoType.Rotate; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ActivateScaleGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionGizmos); _objectSelectionGizmos.ActiveGizmoType = GizmoType.Scale; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ActivateObjectSelectionExtrudeGizmo.IsActive()) { UndoEx.RecordForToolAction(_objectSelectionGizmos); _objectSelectionGizmos.ActiveGizmoType = GizmoType.Duplicate; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); } else if (AllShortcutCombos.Instance.ProjectSelectedObjects.IsActive()) { ProjectSelectionOnProjectionSurface(); } else if (AllShortcutCombos.Instance.SelectionGridSnap.IsActive()) { _selectionGridSnapSession.Begin(); } else if (AllShortcutCombos.Instance.SetRotationToIdentity.IsActive()) { SetWorldRotation(Quaternion.identity); } else if (AllShortcutCombos.Instance.SelectionRotateWorldX.IsActive()) { Rotate(Settings.XRotationStep, Vector3.right); } else if (AllShortcutCombos.Instance.SelectionRotateWorldY.IsActive()) { Rotate(Settings.YRotationStep, Vector3.up); } else if (AllShortcutCombos.Instance.SelectionRotateWorldZ.IsActive()) { Rotate(Settings.ZRotationStep, Vector3.forward); } }
protected override void RenderContent() { EditorGUILayoutEx.BeginVerticalBox(); EditorGUILayout.BeginHorizontal(); const float alignButtonWidth = 72.0f; var content = new GUIContent(); content.text = "Align X"; content.tooltip = "Aligns the positions of the selected objects to the X axis."; if (GUILayout.Button(content, GUILayout.Width(alignButtonWidth))) { ObjectSelectionActions.AlignSelectionToAxis(Axis.X); } content.text = "Align Y"; content.tooltip = "Aligns the positions of the selected objects to the Y axis."; if (GUILayout.Button(content, GUILayout.Width(alignButtonWidth))) { ObjectSelectionActions.AlignSelectionToAxis(Axis.Y); } content.text = "Align Z"; content.tooltip = "Aligns the positions of the selected objects to the Z axis."; if (GUILayout.Button(content, GUILayout.Width(alignButtonWidth))) { ObjectSelectionActions.AlignSelectionToAxis(Axis.Z); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); RenderMakeSelectionStaticButton(); RenderMakeSelectionDynamicButton(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); RenderInvertSelectionButton(); content.text = "Grab settings..."; content.tooltip = "Opens up a new window which allows you to modify selection grab settings."; if (GUILayout.Button(content, GUILayout.Width(110.0f))) { Octave3DWorldBuilder.ActiveInstance.EditorWindowPool.SelectionGrabSettingsWindow.ObjectGrabSettings = ObjectSelection.Get().SelectionGrabSettings; Octave3DWorldBuilder.ActiveInstance.EditorWindowPool.SelectionGrabSettingsWindow.ShowOctave3DWindow(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); RenderAssignSelectionToLayerButton(); RenderSelectionAssignmentLayerSelectionPopup(); EditorGUILayout.EndHorizontal(); if (ObjectGroupDatabase.Get().NumberOfGroups != 0) { if (string.IsNullOrEmpty(ViewData.DestObjectGroupName)) { ViewData.DestObjectGroupName = ObjectGroupDatabase.Get().GetObjectGroupByIndex(0).Name; } else { if (ObjectGroupDatabase.Get().GetObjectGroupByName(ViewData.DestObjectGroupName) == null) { ViewData.DestObjectGroupName = ObjectGroupDatabase.Get().GetObjectGroupByIndex(0).Name; } } EditorGUILayout.BeginHorizontal(); content.text = "Assign to group"; content.tooltip = "Assigns the object selection to the specified object group."; if (GUILayout.Button(content, GUILayout.Width(110.0f))) { ObjectGroup destObjectGroup = ObjectGroupDatabase.Get().GetObjectGroupByName(ViewData.DestObjectGroupName); if (destObjectGroup != null) { ObjectActions.AssignObjectsToGroup(ObjectSelection.Get().GetAllSelectedGameObjects(), destObjectGroup); } } string newGroupName = EditorGUILayoutEx.Popup(new GUIContent(), ViewData.DestObjectGroupName, ObjectGroupDatabase.Get().GetAllObjectGroupNames()); if (newGroupName != ViewData.DestObjectGroupName) { UndoEx.RecordForToolAction(ViewData); ViewData.DestObjectGroupName = newGroupName; } EditorGUILayout.EndHorizontal(); } EditorGUILayoutEx.EndVerticalBox(); }