void OnKeyAction(SceneView sceneView, Event e) { if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.ApplyClip))) { if (e.type == EventType.KeyUp) { ApplyClipPlane(false); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.ApplySplit))) { if (e.type == EventType.KeyUp) { ApplyClipPlane(true); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.InsertEdgeLoop))) { if (e.type == EventType.KeyUp) { InsertEdgeLoop(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.FlipPlane))) { if (e.type == EventType.KeyUp) { isFlipped = !isFlipped; } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.CancelCurrentOperation))) { if (e.type == EventType.KeyUp) { if (planeEstablished) { // If a plane is established ResetTool(); } else { // No plane established, user wants to exit clip tool csgModel.ExitOverrideMode(); } } e.Use(); } }
private void OnKeyAction(SceneView sceneView, Event e) { if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.CancelCurrentOperation))) { if (e.type == EventType.KeyDown) { if (drawMode != DrawMode.None || hitPoints.Count > 0) { // Drawing is in progress so cancel it ResetTool(); } else { // No draw in progress, so user wants to cancel out of draw mode csgModel.ExitOverrideMode(); } } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.Back)) || KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Instance.Delete), false, true)) { if (e.type == EventType.KeyDown) { if (drawMode == DrawMode.PolygonBase) { if (hitPoints.Count > 1) { // Remove the last point hitPoints.RemoveAt(hitPoints.Count - 1); } else { ResetTool(); } } else { ResetTool(); } } e.Use(); } }
void OnKeyAction(SceneView sceneView, Event e) { if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ApplyClip))) { if (e.type == EventType.KeyUp) { ApplyClipPlane(false); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ApplySplit))) { if (e.type == EventType.KeyUp) { ApplyClipPlane(true); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.InsertEdgeLoop))) { if (e.type == EventType.KeyUp) { InsertEdgeLoop(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.FlipPlane))) { if (e.type == EventType.KeyUp) { isFlipped = !isFlipped; } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent("Escape"))) { if (e.type == EventType.KeyUp) { ResetTool(); } e.Use(); } }
public static void OnSceneGUI(SceneView sceneView) { if (Tools.viewTool == ViewTool.FPS) { if (!overrideActive) // Just activated, grab the position { overrideActive = true; activeCameraPosition = SceneView.lastActiveSceneView.camera.transform.position; } Event e = Event.current; // KeyDown events don't change when you press shift after the initial key down, so need to cache this separately isShiftHeld = e.shift; // if(e.type != EventType.Layout && e.type != EventType.Repaint) // { // Debug.Log(e); // } if (e.type == EventType.KeyDown) { // A key has been pressed, so track the relevant direction if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewForwardMapping(), true, false)) { forwardSpeed = 1; } else if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewBackMapping(), true, false)) { forwardSpeed = -1; } if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeRightMapping(), true, false)) { rightSpeed = 1; } else if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeLeftMapping(), true, false)) { rightSpeed = -1; } if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeUpMapping(), true, false)) { upSpeed = 1; } else if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeDownMapping(), true, false)) { upSpeed = -1; } e.Use(); // Debug.Log(e); } else if (e.type == EventType.KeyUp) { // A key has been released so reset the related direction if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewForwardMapping(), true, false)) { forwardSpeed = 0; } else if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewBackMapping(), true, false)) { forwardSpeed = 0; } if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeRightMapping(), true, false)) { rightSpeed = 0; } else if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeLeftMapping(), true, false)) { rightSpeed = 0; } if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeUpMapping(), true, false)) { upSpeed = 0; } else if (KeyMappings.EventsMatch(e, EditorKeyMappings.GetViewStrafeDownMapping(), true, false)) { upSpeed = 0; } e.Use(); } } else { // FPS cam is no longer active, so stop overriding it and reset speeds overrideActive = false; forwardSpeed = 0; rightSpeed = 0; upSpeed = 0; } }
private void OnGenericKeyAction(SceneView sceneView, Event e) { if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ToggleMode)) || KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ToggleModeBack))) { // Toggle mode - immediately (key down) if (e.type == EventType.KeyDown) { int currentModeInt = (int)CurrentSettings.CurrentMode; int count = Enum.GetNames(typeof(MainMode)).Length; if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ToggleModeBack))) { currentModeInt--; } else { currentModeInt++; } if (currentModeInt >= count) { currentModeInt = 0; } else if (currentModeInt < 0) { currentModeInt = count - 1; } SetCurrentMode((MainMode)currentModeInt); SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.IncreasePosSnapping)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { CurrentSettings.ChangePosSnapDistance(2f); SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.DecreasePosSnapping)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { CurrentSettings.ChangePosSnapDistance(.5f); SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.TogglePosSnapping)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { CurrentSettings.PositionSnappingEnabled = !CurrentSettings.PositionSnappingEnabled; SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.IncreaseAngSnapping)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { if (CurrentSettings.AngleSnapDistance >= 15) { CurrentSettings.AngleSnapDistance += 15; } else { CurrentSettings.AngleSnapDistance += 5; } SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.DecreaseAngSnapping)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { if (CurrentSettings.AngleSnapDistance > 15) { CurrentSettings.AngleSnapDistance -= 15; } else { CurrentSettings.AngleSnapDistance -= 5; } SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ToggleAngSnapping)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { CurrentSettings.AngleSnappingEnabled = !CurrentSettings.AngleSnappingEnabled; SceneView.RepaintAll(); } e.Use(); } else if (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ToggleBrushesHidden)) && !SabreGUIHelper.AnyControlFocussed) { if (e.type == EventType.KeyUp) { CurrentSettings.BrushesHidden = !CurrentSettings.BrushesHidden; UpdateBrushVisibility(); SceneView.RepaintAll(); // SceneView.RepaintAll(); } e.Use(); } else if (!mouseIsHeld && (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ChangeBrushToAdditive)) || KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ChangeBrushToAdditive2))) ) { if (e.type == EventType.KeyDown) { bool anyChanged = false; for (int i = 0; i < Selection.gameObjects.Length; i++) { Brush brush = Selection.gameObjects[i].GetComponent <Brush>(); if (brush != null) { Undo.RecordObject(brush, "Change Brush To Add"); brush.Mode = CSGMode.Add; anyChanged = true; } } if (anyChanged) { // Need to update the icon for the csg mode in the hierarchy EditorApplication.RepaintHierarchyWindow(); SceneView.RepaintAll(); } } e.Use(); } else if (!mouseIsHeld && (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ChangeBrushToSubtractive)) || KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.ChangeBrushToSubtractive2))) ) { if (e.type == EventType.KeyDown) { bool anyChanged = false; for (int i = 0; i < Selection.gameObjects.Length; i++) { Brush brush = Selection.gameObjects[i].GetComponent <Brush>(); if (brush != null) { Undo.RecordObject(brush, "Change Brush To Subtract"); brush.Mode = CSGMode.Subtract; anyChanged = true; } } if (anyChanged) { // Need to update the icon for the csg mode in the hierarchy EditorApplication.RepaintHierarchyWindow(); SceneView.RepaintAll(); } } e.Use(); } else if (!mouseIsHeld && (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Group)) && !SabreGUIHelper.AnyControlFocussed) ) { if (e.type == EventType.KeyDown) { if (Selection.activeTransform != null) { List <Transform> selectedTransforms = Selection.transforms.ToList(); selectedTransforms.Sort((x, y) => x.GetSiblingIndex().CompareTo(y.GetSiblingIndex())); Transform rootTransform = Selection.activeTransform.parent; int earliestSiblingIndex = Selection.activeTransform.GetSiblingIndex(); // Make sure we use the earliest sibling index for grouping, as they may select in reverse order up the hierarchy for (int i = 0; i < selectedTransforms.Count; i++) { if (selectedTransforms[i].parent == rootTransform) { int siblingIndex = selectedTransforms[i].GetSiblingIndex(); if (siblingIndex < earliestSiblingIndex) { earliestSiblingIndex = siblingIndex; } } } // Create group GameObject groupObject = new GameObject("Group"); Undo.RegisterCreatedObjectUndo(groupObject, "Group"); Undo.SetTransformParent(groupObject.transform, rootTransform, "Group"); groupObject.transform.position = Selection.activeTransform.position; groupObject.transform.rotation = Selection.activeTransform.rotation; groupObject.transform.localScale = Selection.activeTransform.localScale; // Ensure correct sibling index groupObject.transform.SetSiblingIndex(earliestSiblingIndex); // Renachor for (int i = 0; i < selectedTransforms.Count; i++) { Undo.SetTransformParent(selectedTransforms[i], groupObject.transform, "Group"); } Selection.activeGameObject = groupObject; // EditorApplication.RepaintHierarchyWindow(); // SceneView.RepaintAll(); } } e.Use(); } else if (!mouseIsHeld && (KeyMappings.EventsMatch(e, Event.KeyboardEvent(KeyMappings.Ungroup)) && !SabreGUIHelper.AnyControlFocussed) ) { if (e.type == EventType.KeyDown) { if (Selection.activeTransform != null && Selection.activeGameObject.GetComponents <MonoBehaviour>().Length == 0) { Transform rootTransform = Selection.activeTransform.parent; int siblingIndex = Selection.activeTransform.GetSiblingIndex(); int childCount = Selection.activeTransform.childCount; UnityEngine.Object[] newSelection = new UnityEngine.Object[childCount]; for (int i = 0; i < childCount; i++) { Transform childTransform = Selection.activeTransform.GetChild(0); Undo.SetTransformParent(childTransform, rootTransform, "Ungroup"); childTransform.SetSiblingIndex(siblingIndex + i); newSelection[i] = childTransform.gameObject; } Undo.DestroyObjectImmediate(Selection.activeGameObject); // GameObject.DestroyImmediate(Selection.activeGameObject); Selection.objects = newSelection; } } e.Use(); } }