private void RecordStateAndSelection(IMeshEditor meshEditor, MeshSelection selection, MeshEditorState oldState, MeshEditorState newState) { UndoRedoCallback redo = record => { if (newState != null) { meshEditor.ClearSelection(); meshEditor.SetState(newState); meshEditor.ApplySelection(selection); m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal); OnSelectionChanged(); return(true); } return(false); }; UndoRedoCallback undo = record => { if (oldState != null) { meshEditor.ClearSelection(); meshEditor.SetState(oldState); meshEditor.RollbackSelection(selection); m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal); OnSelectionChanged(); return(true); } return(false); }; m_rte.Undo.CreateRecord(redo, undo); OnSelectionChanged(); }
private void RunStateChangeAction(Action <IMeshEditor> action, bool clearSelection) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { m_rte.Undo.BeginRecord(); m_rte.Undo.BeginRecordTransform(m_pivot); m_rte.Undo.RecordValue(meshEditor, Strong.PropertyInfo((IMeshEditor x) => x.Position)); MeshEditorState oldState = meshEditor.GetState(); action(meshEditor); MeshEditorState newState = meshEditor.GetState(); MeshSelection selection = null; if (clearSelection) { selection = meshEditor.ClearSelection(); } this.RecordState(meshEditor, oldState, newState); if (selection != null) { RecordSelection(meshEditor, selection); } TrySelectPivot(meshEditor); m_rte.Undo.EndRecord(); } }
private void OnSceneLoading() { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { meshEditor.ClearSelection(); } }
private void OnSceneLoading() { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { meshEditor.ClearSelection(); } Mode = ProBuilderToolMode.Object; }
private void OnCurrentModeChanged(ProBuilderToolMode oldMode) { IMeshEditor disabledEditor = m_meshEditors[(int)oldMode]; IMeshEditor enabledEditor = m_meshEditors[(int)m_mode]; GameObject target = null; if (disabledEditor != null) { target = disabledEditor.Target; MeshSelection disabledSelection = disabledEditor.ClearSelection(); MeshSelection selection = null; if (disabledSelection != null) { selection = new MeshSelection(disabledSelection); } if (selection != null) { if (oldMode == ProBuilderToolMode.Face) { if (m_mode == ProBuilderToolMode.Vertex) { selection.FacesToVertices(true); enabledEditor.ApplySelection(selection); } else if (m_mode == ProBuilderToolMode.Edge) { selection.FacesToEdges(true); enabledEditor.ApplySelection(selection); } } else if (oldMode == ProBuilderToolMode.Edge) { if (m_mode == ProBuilderToolMode.Vertex) { selection.EdgesToVertices(true); enabledEditor.ApplySelection(selection); } else if (m_mode == ProBuilderToolMode.Face) { selection.EdgesToFaces(true); enabledEditor.ApplySelection(selection); if (!selection.HasFaces) { m_rte.Selection.activeObject = target; } } } else if (oldMode == ProBuilderToolMode.Vertex) { if (m_mode == ProBuilderToolMode.Face) { selection.VerticesToFaces(true); enabledEditor.ApplySelection(selection); if (!selection.HasFaces) { m_rte.Selection.activeObject = target; } } else if (m_mode == ProBuilderToolMode.Edge) { selection.VerticesToEdges(true); enabledEditor.ApplySelection(selection); if (!selection.HasEdges) { m_rte.Selection.activeObject = target; } } } if (enabledEditor != null && m_rte.Selection.activeObject != m_pivot) { GameObject[] gameObjects = m_rte.Selection.gameObjects; if (gameObjects != null) { enabledEditor.ApplySelection(new MeshSelection(gameObjects)); } } } else { m_rte.Selection.activeObject = target; } if (selection != null) { UndoRedoCallback redo = record => { if (enabledEditor != null) { enabledEditor.ApplySelection(selection); m_pivot.position = enabledEditor.Position; m_pivot.rotation = GetPivotRotation(enabledEditor); OnSelectionChanged(); } return(true); }; UndoRedoCallback undo = record => { if (disabledEditor != null) { disabledEditor.RollbackSelection(disabledSelection); m_pivot.position = disabledEditor.Position; m_pivot.rotation = GetPivotRotation(disabledEditor); OnSelectionChanged(); } return(true); }; m_rte.Undo.CreateRecord(redo, undo); } } else { if (enabledEditor != null) { GameObject[] gameObjects = m_rte.Selection.gameObjects; if (gameObjects != null) { enabledEditor.ApplySelection(new MeshSelection(gameObjects)); OnSelectionChanged(); } } } if (oldMode == ProBuilderToolMode.Object) { SetCanSelect(false); if (disabledEditor != null) { if (disabledEditor.HasSelection) { m_rte.Selection.activeObject = m_pivot.gameObject; } disabledEditor.CenterMode = m_rte.Tools.PivotMode == RuntimePivotMode.Center; } } else if (Mode == ProBuilderToolMode.Object) { SetCanSelect(true); if (m_rte.Selection.activeGameObject == m_pivot.gameObject) { if (disabledEditor != null) { m_rte.Selection.activeObject = target; } else { m_rte.Selection.activeObject = null; } } } if (enabledEditor != null) { m_pivot.position = enabledEditor.Position; m_pivot.rotation = GetPivotRotation(enabledEditor); } }