private void ToggleObjectSelectedState(GameObject gameObject) { ObjectSelection objectSelection = ObjectSelection.Get(); ObjectSelectionUpdateMode selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode; UndoEx.RecordForToolAction(objectSelection); if (selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy) { if (objectSelection.IsGameObjectSelected(gameObject)) { objectSelection.RemoveEntireGameObjectHierarchyFromSelection(gameObject); } else { objectSelection.AddEntireGameObjectHierarchyToSelection(gameObject); } } else { if (objectSelection.IsGameObjectSelected(gameObject)) { objectSelection.RemoveGameObjectFromSelection(gameObject); } else { objectSelection.AddGameObjectToSelection(gameObject); } } objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingMouseClick(); }
public void OnObjectSelectionUpdatedUsingSelectionShape() { ObjectTransformGizmo activeGizmo = GetActiveGizmo(); if (activeGizmo != null) { GameObject firstSelectedGameObject = ObjectSelection.Get().GetFirstSelectedGameObject(); if (firstSelectedGameObject == null) { return; } Transform firstSelectedObjectTransform = firstSelectedGameObject.transform; if (_gizmoTransformPivotPoint == TransformGizmoPivotPoint.Pivot && firstSelectedGameObject != null) { activeGizmo.WorldPosition = firstSelectedObjectTransform.position; } else { activeGizmo.WorldPosition = ObjectSelection.Get().GetWorldCenter(); } if (_gizmoTransformSpace == TransformSpace.Local && firstSelectedObjectTransform != null) { activeGizmo.WorldRotation = firstSelectedObjectTransform.rotation; } else { activeGizmo.WorldRotation = Quaternion.identity; } } }
private void AppendObjectsToSelection(List <GameObject> gameObjectsOverlappedBySelectionShape) { if (gameObjectsOverlappedBySelectionShape.Count != 0) { ObjectSelection objectSelection = ObjectSelection.Get(); ObjectSelectionUpdateMode _selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode; // Note: We only continue if the current object selection is not the same as the // collection of objects we are appending. If it is, we would be registering // an unnecessary Undo operation. if (!objectSelection.IsSameAs(gameObjectsOverlappedBySelectionShape)) { if (_selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy) { UndoEx.RecordForToolAction(objectSelection); objectSelection.AddEntireGameObjectHierarchyToSelection(gameObjectsOverlappedBySelectionShape); } else { UndoEx.RecordForToolAction(objectSelection); objectSelection.AddGameObjectCollectionToSelection(gameObjectsOverlappedBySelectionShape); } objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingSelectionShape(); } } }
public static void SaveConfig(string fileName, Octave3DConfigSaveLoadSettings saveSettings) { if (string.IsNullOrEmpty(fileName)) { return; } using (XmlTextWriter xmlWriter = new XmlTextWriter(fileName, Encoding.UTF8)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteNewLine(0); xmlWriter.WriteStartElement(Octave3DConfigXMLInfo.RootNode); SaveSnapSettings(xmlWriter, saveSettings); SaveObjectSelectionSettings(xmlWriter, saveSettings); SaveObjectErasingSettings(xmlWriter, saveSettings); SaveMirrorLookAndFeel(ObjectPlacement.Get().MirrorRenderSettings, xmlWriter, saveSettings, true); SaveMirrorLookAndFeel(ObjectSelection.Get().MirrorRenderSettings, xmlWriter, saveSettings, false); SaveSnapLookAndFeel(xmlWriter, saveSettings); SaveObjectPlacementLookAndFeel(xmlWriter, saveSettings); SaveObjectSelectionLookAndFeel(xmlWriter, saveSettings); SaveObjectErasingLookAndFeel(xmlWriter, saveSettings); xmlWriter.WriteNewLine(0); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); } }
private void RenderAssignSelectedObjectsToActiveLayerButton() { if (GUILayout.Button(GetContentForAssignSelectedObjectsToActiveLayerButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth * _actionButtonScale))) { ObjectLayerDatabase.Get().AssignObjectsToLayer(ObjectSelection.Get().GetAllSelectedGameObjects(), _database.ActiveLayer); } }
public void OnObjectSelectionUpdatedUsingMouseClick() { ObjectGizmo activeGizmo = GetActiveGizmo(); if (activeGizmo != null) { GameObject lastSelectedGameObject = ObjectSelection.Get().GetLastSelectedGameObject(); if (lastSelectedGameObject == null) { return; } Transform lastSelectedObjectTransform = lastSelectedGameObject.transform; if (_gizmoTransformPivotPoint == TransformGizmoPivotPoint.Pivot && lastSelectedGameObject != null && _activeGizmoType != GizmoType.Duplicate) { activeGizmo.WorldPosition = lastSelectedObjectTransform.position; } else { activeGizmo.WorldPosition = ObjectSelection.Get().GetWorldCenter(); } if (_gizmoTransformSpace == TransformSpace.Local && lastSelectedGameObject != null && _activeGizmoType != GizmoType.Duplicate) { activeGizmo.WorldRotation = lastSelectedObjectTransform.rotation; } else { activeGizmo.WorldRotation = Quaternion.identity; } } }
private void UpdateSelectionForNoAppendAndNoDeselect(List <GameObject> gameObjectsOverlappedBySelectionShape) { ObjectSelection objectSelection = ObjectSelection.Get(); ObjectSelectionUpdateMode _selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode; // If no object was overlapped by the selection shape, we can clear the selection. // Note: We only clear the selection if the current number of selected objects is not 0. This // allows us to avoid registering an Undo for nothing. if (gameObjectsOverlappedBySelectionShape.Count == 0 && objectSelection.NumberOfSelectedObjects != 0) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); } else // When the selection shape has overlapped objects, we must reset the selection by clearing it and selecting only // the objects which were overlapped. if (gameObjectsOverlappedBySelectionShape.Count != 0) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); if (_selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy) { objectSelection.AddEntireGameObjectHierarchyToSelection(gameObjectsOverlappedBySelectionShape); } else { objectSelection.AddGameObjectCollectionToSelection(gameObjectsOverlappedBySelectionShape); } objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingSelectionShape(); } }
public static void DeselectAllObjectsInLayer(int objectLayer) { List <GameObject> allObjectsInLayer = ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer); ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allObjectsInLayer); ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated(); }
public static void SelectAllObjectsWithSamePrefabAsObject(GameObject gameObject) { GameObject root = Octave3DWorldBuilder.ActiveInstance.GetRoot(gameObject); if (root == null) { return; } GameObject sourcePrefab = root.GetSourcePrefab(); if (sourcePrefab == null) { return; } ObjectSelection objectSelection = ObjectSelection.Get(); List <GameObject> workingObjects = Octave3DWorldBuilder.ActiveInstance.GetAllWorkingObjects(); foreach (GameObject workingObject in workingObjects) { GameObject workingObjectRoot = Octave3DWorldBuilder.ActiveInstance.GetRoot(workingObject); if (workingObjectRoot == null) { continue; } GameObject workingObjectSourcePrefab = workingObjectRoot.GetSourcePrefab(); if (workingObjectSourcePrefab != null && workingObjectSourcePrefab == sourcePrefab) { objectSelection.AddGameObjectCollectionToSelection(workingObjectRoot.GetAllChildrenIncludingSelf()); } } }
public static void AlignSelectionToAxis(Axis axis) { int axisIndex = (int)axis; List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects(); List <GameObject> selectedParents = GameObjectExtensions.GetParents(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 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 ClearSelectionAndSelectObject(GameObject gameObject) { ObjectSelection objectSelection = ObjectSelection.Get(); ObjectSelectionUpdateMode selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode; if (selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); objectSelection.AddEntireGameObjectHierarchyToSelection(gameObject); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingMouseClick(); } else { // Note: We only continue if the picked object is not the only currently selected object. If it is, it means // we would be registering an Undo operation for nothing. if (!ObjectSelection.Get().IsSameAs(gameObject)) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); objectSelection.AddGameObjectToSelection(gameObject); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingMouseClick(); } } }
private void RenderInvertSelectionButton() { if (GUILayout.Button(GetContentForInvertSelection(), GUILayout.Width(110.0f))) { UndoEx.RecordForToolAction(ObjectSelection.Get()); ObjectSelectionActions.InvertSelection(); } }
private void RenderDeselectActiveLayerButton() { if (GUILayout.Button(GetContentForDeselectActiveLayerButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth * _actionButtonScale))) { UndoEx.RecordForToolAction(ObjectSelection.Get()); ObjectSelectionActions.DeselectAllObjectsInLayer(_database.ActiveLayer); } }
private void RenderEraseAllLayersButton() { if (GUILayout.Button(GetContentForEraseAllLayersButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth * _actionButtonScale))) { UndoEx.RecordForToolAction(ObjectSelection.Get()); ObjectActions.EraseGameObjectsInAllLayers(); } }
private void PerformNecessaryUndoRecordingsBeforeEraseOperation() { // Note: We have to increment the current group, because otherwise the previous records will be overridden // by the new one and we would not be able to properly restore the states on Undo. For example, this // can result in loosing the object selection information. UndoEx.IncrementCurrentGroup(); UndoEx.RecordForToolAction(ObjectSelection.Get()); }
protected override void RenderContent() { ObjectSelection objectSelection = ObjectSelection.Get(); objectSelection.RectangleSelectionShapeRenderSettings.View.Render(); objectSelection.EllipseSelectionShapeRenderSettings.View.Render(); ObjectSelectionRenderSettings.Get().View.Render(); }
private GUIContent GetContentForGizmoTransformPivotPointSelectionPopup() { var content = new GUIContent(); content.text = ""; content.tooltip = "Pivot point: " + ObjectSelection.Get().ObjectSelectionTransformGizmoSystem.GizmoTransformPivotPoint; return(content); }
private GUIContent GetContentForGizmoTransformSpaceSelectionPopup() { var content = new GUIContent(); content.text = ""; content.tooltip = "Transform space: " + ObjectSelection.Get().ObjectSelectionTransformGizmoSystem.GizmoTransformSpace; return(content); }
public static void AppendAllObjectsInLayerToSelection(int objectLayer) { List <GameObject> allObjectsInLayer = ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer); ObjectSelection objectSelection = ObjectSelection.Get(); objectSelection.AddGameObjectCollectionToSelection(allObjectsInLayer); ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated(); }
protected override void PerformDrop() { string[] folderPaths = DragAndDrop.paths; if (folderPaths.Length > 0) { UndoEx.RecordForToolAction(ObjectSelection.Get().PrefabCreationSettings); ObjectSelection.Get().PrefabCreationSettings.DestinationFolder = folderPaths[0]; } }
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 RenderActionControls() { EditorGUILayout.BeginHorizontal(); RenderCreateNewGroupButton(); RenderCreateNewGroupNameChangeTextField(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); var content = new GUIContent(); content.text = "Remove"; content.tooltip = "Removes the active group. The associated object will remain in the scene but it will no longer be regarded as a group."; if (GUILayout.Button(content, GUILayout.Width(100.0f))) { ObjectGroup objectGroup = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.ActiveGroup; if (objectGroup != null && objectGroup.GroupObject != null) { Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.MakeNoLongerGroup(objectGroup.GroupObject); } } content.text = "Remove all"; content.tooltip = "Removes all groups. The associated objects will remain in the scene but they will no longer be regarded as groups."; if (GUILayout.Button(content, GUILayout.Width(100.0f))) { ObjectGroup objectGroup = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.ActiveGroup; if (objectGroup != null && objectGroup.GroupObject != null) { Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.MakeAllNoLongerGroup(); } } RenderDestroyActiveGroupButton(); RenderDestroyAllGroupsButton(); EditorGUILayout.EndHorizontal(); if (_database.ActiveGroup != null) { EditorGUILayout.BeginHorizontal(); content.text = "Select"; content.tooltip = "Selects the active group."; if (GUILayout.Button(content, GUILayout.Width(100.0f))) { ObjectGroup objectGroup = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.ActiveGroup; UndoEx.RecordForToolAction(ObjectSelection.Get()); ObjectSelection.Get().Clear(); ObjectSelection.Get().AddGameObjectCollectionToSelection(objectGroup.GroupObject.GetAllChildren()); ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated(); SceneView.RepaintAll(); } RenderMakeActiveGroupStaticButton(); RenderMakeActiveGroupDynamicButton(); EditorGUILayout.EndHorizontal(); } }
public static void SelectAllObjectsInLayer(int objectLayer) { List <GameObject> allObjectsInLayer = ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer); ObjectSelection objectSelection = ObjectSelection.Get(); objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(allObjectsInLayer); ObjectSelection.Get().ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated(); }
public void Begin() { if (_state != State.Inactive) { return; } _state = State.SelectPivot; _selectedParents = GameObjectExtensions.GetParents(ObjectSelection.Get().GetAllSelectedGameObjects()); }
private void RenderGizmoTransformPivotPointSelectionPopup() { ObjectSelectionTransformGizmoSystem selectionGizmoTransformSystem = ObjectSelection.Get().ObjectSelectionTransformGizmoSystem; TransformGizmoPivotPoint newPivotPoint = (TransformGizmoPivotPoint)EditorGUILayout.EnumPopup(GetContentForGizmoTransformPivotPointSelectionPopup(), selectionGizmoTransformSystem.GizmoTransformPivotPoint, GUILayout.Width(_selectionGizmoSpecificPopupWidth)); if (newPivotPoint != selectionGizmoTransformSystem.GizmoTransformPivotPoint) { UndoEx.RecordForToolAction(selectionGizmoTransformSystem); selectionGizmoTransformSystem.GizmoTransformPivotPoint = newPivotPoint; } }
private void RenderGizmoTransformSpaceSelectionPopup() { ObjectSelectionTransformGizmoSystem selectionGizmoTransformSystem = ObjectSelection.Get().ObjectSelectionTransformGizmoSystem; TransformSpace newTransformSpace = (TransformSpace)EditorGUILayout.EnumPopup(GetContentForGizmoTransformSpaceSelectionPopup(), selectionGizmoTransformSystem.GizmoTransformSpace, GUILayout.Width(_selectionGizmoSpecificPopupWidth)); if (newTransformSpace != selectionGizmoTransformSystem.GizmoTransformSpace) { UndoEx.RecordForToolAction(selectionGizmoTransformSystem); selectionGizmoTransformSystem.GizmoTransformSpace = newTransformSpace; } }
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); }
private static void PrepareGameObjectCollectionForEraseOperation(IEnumerable <GameObject> gameObjects) { ObjectSelection objectSelection = ObjectSelection.Get(); // Note: Before objects are erased, we have to remove them from the object selection. // Otherwise, the selection information will be lost when performing an Undo // operation. I can't figure out why this is :). foreach (GameObject gameObject in gameObjects) { objectSelection.RemoveGameObjectFromSelection(gameObject); } }
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>()); }