private void PlaceBlock() { List <GameObject> placedHierarchyRoots = Octave3DScene.Get().InstantiateObjectHirarchiesFromPlacementDataCollection(_objectPlacementBlock.EndManualConstruction()); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoots, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement); ObjectPlacementGuide.Active = true; }
private void PlaceObjects() { if (CanPlaceObjectsOnHoveredSurface()) { var placementDataInstances = _objectPlacementDataCalculator.Calculate(RotationToApplyForStrokeAlignment); List <GameObject> placedHierarchyRoots = Octave3DScene.Get().InstantiateObjectHirarchiesFromPlacementDataCollection(placementDataInstances); for (int rootIndex = 0; rootIndex < placedHierarchyRoots.Count; ++rootIndex) { GameObject root = placedHierarchyRoots[rootIndex]; if (placementDataInstances[rootIndex].MustEmbedInSurface) { if (_strokeSurface.Type == DecorPaintStrokeSurfaceType.Terrain) { root.EmbedInSurfaceByVertex(-Vector3.up, _strokeSurface.SurfaceObject); } else if (_strokeSurface.Type == DecorPaintStrokeSurfaceType.Mesh) { root.EmbedInSurfaceByVertex(-_strokeSurface.Plane.normal, _strokeSurface.SurfaceObject); } } } List <GameObject> allPlacedObjects = GameObjectExtensions.GetAllObjectsInHierarchyCollection(placedHierarchyRoots); _objectsPlacedWhileDragging.AddRange(allPlacedObjects); DecorPaintObjectPlacement.Get().DecorPaintMask.ObjectCollectionMask.Mask(allPlacedObjects); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoots, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement); } RegisterPlacementPoint(); }
private void PlaceObjectFromPlacementGuide(bool checkForIntersection) { ObjectPlacementGuide placementGuide = ObjectPlacementGuide.Instance; GameObject placedHierarchyRoot = null; OrientedBox guideHierarchyWorldOrientedBox = ObjectPlacementGuide.SceneObject.GetHierarchyWorldOrientedBox(); List <GameObject> intersectingObjects = ObjectQueries.GetIntersectingObjects(guideHierarchyWorldOrientedBox, new List <GameObject> { _strokeSurface.SurfaceObject }, true); if (!checkForIntersection || ObjectPlacementSettings.Get().ObjectIntersectionSettings.AllowIntersectionForDecorPaintSingleModeDrag || intersectingObjects.Count == 0) { placedHierarchyRoot = Octave3DScene.Get().InstantiateObjectHierarchyFromPrefab(placementGuide.SourcePrefab, placementGuide.gameObject.transform); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoot, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement); List <GameObject> allPlacedObjects = placedHierarchyRoot.GetAllChildrenIncludingSelf(); _objectsPlacedWhileDragging.AddRange(allPlacedObjects); DecorPaintObjectPlacement.Get().DecorPaintMask.ObjectCollectionMask.Mask(allPlacedObjects); } _orientedBoxOfLastPlacedHierarchy = ObjectPlacementGuide.SceneObject.GetHierarchyWorldOrientedBox(); _pivotPointsOfLastPlacedHierarchy.FromOrientedBoxAndDecorStrokeSurface(_orientedBoxOfLastPlacedHierarchy, _strokeSurface); if (DecorPaintObjectPlacementSettings.Get().SingleDecorPaintModeSettings.RandomizePrefabsInActiveCategory) { PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory; if (activePrefabCategory != null) { activePrefabCategory.RandomizeActivePrefab(); } } }
public static void SendToInterestedListeners(GameObject placedRoot, PlacementType objectPlacementType) { var message = new ObjectHierarchyRootsWerePlacedInSceneMessage(new List <GameObject> { placedRoot }, objectPlacementType); MessageListenerDatabase.Instance.SendMessageToInterestedListeners(message); }
public static void DuplicateSelection() { if (ObjectSelection.Get().NumberOfSelectedObjects == 0) { return; } ObjectSelection objectSelection = ObjectSelection.Get(); List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects(); List <GameObject> selectedParents = GameObjectExtensions.GetParents(allSelectedObjects); var clonedObjects = new List <GameObject>(); var clonedParents = 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()); Octave3DScene.Get().RegisterObjectHierarchy(clonedParent); clonedParents.Add(clonedParent); } else { GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale); clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); Octave3DScene.Get().RegisterObjectHierarchy(clonedParent); clonedParents.Add(clonedParent); } } if (clonedObjects.Count != 0) { objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(clonedObjects); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdated(); } if (clonedParents.Count != 0) { ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(clonedParents, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection); } SceneViewCamera.Instance.SetObjectVisibilityDirty(); }
private void PlaceObjects() { if (CanPlaceObjectsOnHoveredSurface()) { var placementDataInstances = _objectPlacementDataCalculator.Calculate(RotationToApplyForStrokeAlignment); List <GameObject> placedHierarchyRoots = Octave3DScene.Get().InstantiateObjectHirarchiesFromPlacementDataCollection(placementDataInstances); List <GameObject> allPlacedObjects = GameObjectExtensions.GetAllObjectsInHierarchyCollection(placedHierarchyRoots); _objectsPlacedWhileDragging.AddRange(allPlacedObjects); DecorPaintObjectPlacement.Get().DecorPaintMask.ObjectCollectionMask.Mask(allPlacedObjects); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoots, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement); } RegisterPlacementPoint(); }
private void PlaceObject() { ObjectPlacementGuide placementGuide = ObjectPlacementGuide.Instance; GameObject placedHierarchyRoot = Octave3DScene.Get().InstantiateObjectHierarchyFromPrefab(placementGuide.SourcePrefab, placementGuide.WorldPosition, placementGuide.WorldRotation, placementGuide.WorldScale); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoot, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement); if (PointAndClickObjectPlacementSettings.Get().RandomizePrefabsInActiveCategory) { PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory; if (activePrefabCategory != null) { activePrefabCategory.RandomizeActivePrefab(); } } }
public void HandleMouseButtonDownEvent(Event e) { if (ObjectPlacementGuide.ExistsInScene && _objectPlacementPath.IsUnderManualConstruction && AllShortcutCombos.Instance.PlacePathOnClick.IsActive()) { e.DisableInSceneView(); List <GameObject> placedHierarchyRoots = Octave3DScene.Get().InstantiateObjectHirarchiesFromPlacementDataCollection(_objectPlacementPath.EndManualConstruction()); ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(placedHierarchyRoots, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.ObjectPlacement); if (ObjectPlacementGuide.ExistsInScene) { ObjectPlacementGuide.Active = true; } return; } if (_objectPlacementPath.IsUnderManualConstruction && AllShortcutCombos.Instance.ManualAttach2NewSegmentsToPath.IsActive()) { e.DisableInSceneView(); _objectPlacementPath.Attach2NewSegmentsIfUnderManualConstruction(); } if (!_objectPlacementPath.IsUnderManualConstruction && AllShortcutCombos.Instance.BeginManualPathConstruction.IsActive() && e.InvolvesLeftMouseButton()) { e.DisableInSceneView(); if (ObjectPlacementGuide.ExistsInScene) { _objectPlacementPath.SetStartObject(ObjectPlacementGuide.SceneObject); _objectPlacementPath.BeginManualConstruction(); if (_objectPlacementPath.IsUnderManualConstruction) { ObjectPlacementGuide.Active = false; } } else { Debug.LogWarning("Can not begin path construction because the placement guide does not exist in the scene. Please activate a prefab to start construction."); } } }
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); } }