private void OnBeginMove(BaseHandle positionHandle) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { positionHandle.EnableUndo = false; m_rte.Undo.BeginRecord(); if (UVEditingMode) { m_rte.Undo.BeginRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.offset)); } else { m_rte.Undo.BeginRecordTransform(m_pivot); m_rte.Undo.RecordValue(meshEditor, Strong.PropertyInfo((IMeshEditor x) => x.Position)); m_shift = m_rte.Input.GetKey(KeyCode.LeftShift); if (m_shift) { MeshEditorState oldState = meshEditor.GetState(); meshEditor.Extrude(); this.RecordState(meshEditor, oldState, null, false); } } m_rte.Undo.EndRecord(); m_initialUVOffset = UV.offset; } }
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 RefreshSelectionAndPivotPoint() { m_selection.Clear(); IMeshEditor editor = m_tool.GetEditor(); if (editor == null) { return; } MeshSelection meshSelection = editor.GetSelection(); if (meshSelection != null) { foreach (PBMesh mesh in meshSelection.GetSelectedMeshes()) { ManualUVSelection uvSelection = new ManualUVSelection(mesh.gameObject); m_selection.Add(uvSelection); if (MeshSelected != null) { MeshSelected(uvSelection); } } Select(meshSelection); } RefreshPivotPoint(); }
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 OnBoxSelection(object sender, BoxSelectionArgs e) { IMeshEditor meshEditor = m_meshEditors[(int)m_mode]; if (meshEditor == null) { return; } RuntimeWindow window = m_rte.ActiveWindow; Vector2 min = m_boxSelection.SelectionBounds.min; Vector2 max = m_boxSelection.SelectionBounds.max; RectTransform rt = window.GetComponent <RectTransform>(); Rect rect = new Rect(new Vector2(min.x, rt.rect.height - max.y), m_boxSelection.SelectionBounds.size); MeshSelection selection = meshEditor.Select(window.Camera, rect, e.GameObjects.Where(g => g.GetComponent <ExposeToEditor>() != null).ToArray(), MeshEditorSelectionMode.Add); m_rte.Undo.BeginRecord(); if (selection != null) { RecordSelection(meshEditor, selection); } m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor); TrySelectPivot(meshEditor); m_rte.Undo.EndRecord(); }
private void OnEndMove(BaseHandle positionHandle) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { positionHandle.EnableUndo = true; m_rte.Undo.BeginRecord(); if (UVEditingMode) { m_pivot.position = meshEditor.Position; m_rte.Undo.EndRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.offset)); } else { MeshEditorState newState = meshEditor.GetState(); this.RecordState(meshEditor, null, newState, false, false); m_rte.Undo.EndRecordTransform(m_pivot); m_rte.Undo.RecordValue(meshEditor, Strong.PropertyInfo((IMeshEditor x) => x.Position)); } m_rte.Undo.EndRecord(); } }
public static void RecordState(this IProBuilderTool tool, IMeshEditor meshEditor, MeshEditorState oldState, MeshEditorState newState, bool oldStateChanged = true, bool newStateChanged = true) { UndoRedoCallback redo = record => { if (newState != null) { meshEditor.SetState(newState); return(newStateChanged); } return(false); }; UndoRedoCallback undo = record => { if (oldState != null) { meshEditor.SetState(oldState); return(oldStateChanged); } return(false); }; IOC.Resolve <IRTE>().Undo.CreateRecord(redo, undo); }
public void ApplyMaterial(Material material, Camera camera, Vector3 mousePosition) { IMeshEditor editor = GetEditor(); if (editor != null) { MeshSelection selection = editor.GetSelection(); ApplyMaterialResult result = m_materialEditor.ApplyMaterial(material, selection, camera, mousePosition); RecordApplyMaterialResult(result); } else { GameObject gameObject = PBUtility.PickObject(camera, mousePosition); if (gameObject != null) { if (m_rte.Selection.IsSelected(gameObject)) { ApplyMaterialToSelectedGameObjects(material); } else { ApplyMaterialResult result = m_materialEditor.ApplyMaterial(material, gameObject); RecordApplyMaterialResult(result); } } } }
private void OnSceneLoading() { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { meshEditor.ClearSelection(); } }
private void OnUVChanged() { IMeshEditor editor = GetEditor(); if (editor != null) { MeshSelection selection = editor.GetSelection(); m_autoUVEditor.ApplySettings(m_uv, selection); } }
private void OnSceneLoading() { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { meshEditor.ClearSelection(); } Mode = ProBuilderToolMode.Object; }
public static void Extrude(this IProBuilderTool tool, float distance) { IMeshEditor meshEditor = tool.GetEditor(); MeshEditorState oldState = meshEditor.GetState(); meshEditor.Extrude(distance); MeshEditorState newState = meshEditor.GetState(); tool.UpdatePivot(); tool.RecordState(meshEditor, oldState, newState); }
private void TrySelectPivot(IMeshEditor meshEditor) { if (meshEditor.HasSelection) { m_rte.Selection.activeObject = m_pivot.gameObject; } else { m_rte.Selection.activeObject = null; } }
public void SelectHoles() { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { MeshSelection selection = meshEditor.SelectHoles(); if (selection != null) { RecordSelection(meshEditor, selection); } } }
private void OnSelectionChanged() { IMeshEditor editor = GetEditor(); if (editor != null) { MeshSelection selection = editor.GetSelection(); PBAutoUnwrapSettings settings = m_autoUVEditor.GetSettings(selection); m_uv.CopyFrom(settings); } if (SelectionChanged != null) { SelectionChanged(); } }
public static void RecordStateWithAction(this IProBuilderTool tool, IMeshEditor meshEditor, MeshEditorState oldState, Action <Record> newState, bool changed = true) { UndoRedoCallback redo = record => { newState(record); return(changed); }; UndoRedoCallback undo = record => { meshEditor.SetState(oldState); return(true); }; IOC.Resolve <IRTE>().Undo.CreateRecord(redo, undo); }
private void OnSelectionChanged() { m_selection = null; IMeshEditor meshEditor = m_proBuilderTool.GetEditor(); if (meshEditor == null) { return; } m_selection = meshEditor.GetSelection(); ClearSmoothGroups(); CreateSmoothGroups(); UpdateEditorsPanel(); }
private void OnBeginScale(BaseHandle scaleHandle) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { scaleHandle.EnableUndo = false; m_pivot.localScale = Vector3.one; m_initialUVScale = UV.scale; if (UVEditingMode) { m_rte.Undo.BeginRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.scale)); } meshEditor.BeginScale(); } }
private void OnClear(object sender, EventArgs e) { SmoothGroupEditor editor = (SmoothGroupEditor)sender; PBMesh pbMesh = editor.Data.PBMesh; IMeshEditor meshEditor = m_proBuilderTool.GetEditor(); MeshEditorState oldState = meshEditor.GetState(false); PBSmoothing.ClearGroup(pbMesh, meshEditor.GetSelection()); m_smoothGroups[pbMesh].Rebuild(pbMesh); m_proBuilderTool.TryUpdatePivotTransform(); MeshEditorState newState = meshEditor.GetState(false); m_proBuilderTool.RecordState(oldState, newState, true); }
public void ApplyMaterial(Material material) { IMeshEditor editor = GetEditor(); if (editor != null) { MeshSelection selection = editor.GetSelection(); // m_rte.Undo.BeginRecord(); ApplyMaterialResult result = m_materialEditor.ApplyMaterial(material, selection); RecordApplyMaterialResult(result); } else { ApplyMaterialToSelectedGameObjects(material); } }
private void UpdateEditorsPanel() { foreach (Transform child in m_contentPanel) { SmoothGroupEditor editor = child.GetComponent <SmoothGroupEditor>(); Unsubscribe(editor); Destroy(child.gameObject); } IMeshEditor meshEditor = m_proBuilderTool.GetEditor(); if (meshEditor == null) { return; } MeshSelection selection = meshEditor.GetSelection(); if (selection == null) { return; } selection = selection.ToFaces(false); if (!selection.HasFaces) { return; } const int maxVisibleGroups = 8; int index = 0; foreach (PBMesh pbMesh in selection.GetSelectedMeshes()) { index++; if (index == maxVisibleGroups) { return; } SmoothGroupEditor editor = Instantiate(m_groupPrefab, m_contentPanel); editor.Data = m_smoothGroups[pbMesh]; Subscribe(editor); } }
private void UpdateGlobalMode() { foreach (IMeshEditor editor in m_meshEditors) { if (editor == null) { continue; } editor.GlobalMode = m_rte.Tools.PivotRotation == RuntimePivotRotation.Global; } IMeshEditor currentEditor = GetEditor(); if (currentEditor != null) { m_pivot.rotation = GetPivotRotation(currentEditor); } }
private void OnBeginRotate(BaseHandle rotationHandle) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { rotationHandle.EnableUndo = false; m_initialRotation = GetPivotRotation(meshEditor); m_pivot.rotation = m_initialRotation; m_initialRight = m_pivot.TransformDirection(Vector3.right); m_initialUVRotation = UV.rotation; if (UVEditingMode) { m_rte.Undo.BeginRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.rotation)); } meshEditor.BeginRotate(m_initialRotation); } }
private void UpdateCenterMode() { foreach (IMeshEditor editor in m_meshEditors) { if (editor == null) { continue; } editor.CenterMode = m_rte.Tools.PivotMode == RuntimePivotMode.Center; } IMeshEditor meshEditor = m_meshEditors[(int)m_mode]; if (meshEditor != null) { m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor); } }
private void OnEndRotate(BaseHandle rotationHandle) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { rotationHandle.EnableUndo = true; Quaternion initialRotation = m_initialRotation; Quaternion endRotation = m_pivot.rotation; meshEditor.EndRotate(); Quaternion newStartRotation = GetPivotRotation(meshEditor); m_pivot.rotation = newStartRotation; if (UVEditingMode) { m_rte.Undo.EndRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.rotation)); } else { m_rte.Undo.CreateRecord(record => { meshEditor.BeginRotate(initialRotation); meshEditor.Rotate(endRotation); meshEditor.EndRotate(); m_pivot.transform.rotation = newStartRotation; return(true); }, record => { meshEditor.BeginRotate(endRotation); meshEditor.Rotate(initialRotation); meshEditor.EndRotate(); m_pivot.transform.rotation = initialRotation; return(true); }); } } }
public void UnselectFaces(Material material) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { MeshSelection selection = meshEditor.Unselect(material); m_rte.Undo.BeginRecord(); if (selection != null) { RecordSelection(meshEditor, selection); } m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor); TrySelectPivot(meshEditor); m_rte.Undo.EndRecord(); } }
private void UpdateGlobalMode() { if (m_mode == ProBuilderToolMode.PolyShape) { return; } foreach (IMeshEditor editor in m_meshEditors) { if (editor == null) { continue; } editor.GlobalMode = m_rte.Tools.PivotRotation == RuntimePivotRotation.Global; } IMeshEditor currentEditor = GetEditor(); if (currentEditor != null) { m_pivot.rotation = GetPivotRotation(currentEditor); } }
private void RecordSelection(IMeshEditor meshEditor, MeshSelection selection) { UndoRedoCallback redo = record => { meshEditor.ApplySelection(selection); m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal); OnSelectionChanged(); return(true); }; UndoRedoCallback undo = record => { meshEditor.RollbackSelection(selection); m_pivot.position = meshEditor.Position; m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal); OnSelectionChanged(); return(true); }; m_rte.Undo.CreateRecord(redo, undo); OnSelectionChanged(); }
private void OnExpandSelection(object sender, EventArgs e) { IMeshEditor meshEditor = m_proBuilderTool.GetEditor(); MeshSelection selection = meshEditor.GetSelection(); MeshEditorState oldState = meshEditor.GetState(false); selection = PBSmoothing.ExpandSelection(selection); if (m_proBuilderTool.Mode == ProBuilderToolMode.Vertex) { selection = selection.ToVertices(false); } else if (m_proBuilderTool.Mode == ProBuilderToolMode.Edge) { selection = selection.ToEdges(false); } meshEditor.SetSelection(selection); m_proBuilderTool.TryUpdatePivotTransform(); MeshEditorState newState = meshEditor.GetState(false); m_proBuilderTool.RecordState(oldState, newState, true); }
private void OnEndScale(BaseHandle scaleHandle) { IMeshEditor meshEditor = GetEditor(); if (meshEditor != null) { scaleHandle.EnableUndo = true; meshEditor.EndScale(); Vector3 newScale = m_pivot.localScale; Quaternion rotation = m_pivot.rotation; m_pivot.localScale = Vector3.one; if (UVEditingMode) { m_rte.Undo.EndRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.scale)); } else { m_rte.Undo.CreateRecord(record => { meshEditor.BeginScale(); meshEditor.Scale(newScale, rotation); meshEditor.EndScale(); return(true); }, record => { meshEditor.BeginScale(); meshEditor.Scale(new Vector3(1.0f / newScale.x, 1.0f / newScale.y, 1.0f / newScale.z), rotation); meshEditor.EndRotate(); return(true); }); } } }