public static void DoViewTool(Transform cameraTransform, SceneView view) { Event current = Event.current; int num = SceneViewMotion.s_ViewToolID; EventType typeForControl = current.GetTypeForControl(num); float d = 0f; if (view && Tools.s_LockedViewTool == ViewTool.FPS) { view.FixNegativeSize(); d = (view.pivot - cameraTransform.position).magnitude; } switch (typeForControl) { case EventType.MouseDown: SceneViewMotion.HandleMouseDown(view, num, current.button); break; case EventType.MouseUp: SceneViewMotion.HandleMouseUp(view, num, current.button, current.clickCount); break; case EventType.MouseDrag: SceneViewMotion.HandleMouseDrag(cameraTransform, view, num); break; case EventType.KeyDown: SceneViewMotion.HandleKeyDown(view); break; case EventType.KeyUp: SceneViewMotion.HandleKeyUp(); break; case EventType.ScrollWheel: SceneViewMotion.HandleScrollWheel(view, !current.alt); break; case EventType.Layout: { Vector3 movementDirection = SceneViewMotion.GetMovementDirection(); if (GUIUtility.hotControl == num && movementDirection.sqrMagnitude != 0f) { cameraTransform.position += cameraTransform.rotation * movementDirection; } break; } } if (view && Tools.s_LockedViewTool == ViewTool.FPS) { if (!view.orthographic) { view.rotation = cameraTransform.rotation; } view.pivot = cameraTransform.position + cameraTransform.forward * d; view.Repaint(); } }
public static void DoViewTool(SceneView view) { Event current = Event.current; int num = SceneViewMotion.s_ViewToolID; EventType typeForControl = current.GetTypeForControl(num); if (view && Tools.s_LockedViewTool == ViewTool.FPS) { view.FixNegativeSize(); } switch (typeForControl) { case EventType.MouseDown: SceneViewMotion.HandleMouseDown(view, num, current.button); break; case EventType.MouseUp: SceneViewMotion.HandleMouseUp(view, num, current.button, current.clickCount); break; case EventType.MouseDrag: SceneViewMotion.HandleMouseDrag(view, num); break; case EventType.KeyDown: SceneViewMotion.HandleKeyDown(view); break; case EventType.KeyUp: SceneViewMotion.HandleKeyUp(); break; case EventType.ScrollWheel: SceneViewMotion.HandleScrollWheel(view, view.in2DMode == current.alt); break; case EventType.Layout: { Vector3 movementDirection = SceneViewMotion.GetMovementDirection(); if (GUIUtility.hotControl == num && movementDirection.sqrMagnitude != 0f) { view.pivot += view.rotation * movementDirection; view.Repaint(); } break; } case EventType.Used: if (GUIUtility.hotControl != num && SceneViewMotion.s_CurrentState != SceneViewMotion.MotionState.kInactive) { SceneViewMotion.ResetDragState(); } break; } }
private static void HandleKeyDown(SceneView sceneView) { if (Event.current.keyCode == KeyCode.Escape && GUIUtility.hotControl == SceneViewMotion.s_ViewToolID) { SceneViewMotion.ResetDragState(); } if (Tools.s_LockedViewTool != ViewTool.FPS) { return; } Event current = Event.current; Vector3 motion = SceneViewMotion.s_Motion; if (current.keyCode == (Event)SceneViewMotion.kFPSForward.keyCode) { sceneView.viewIsLockedToObject = false; SceneViewMotion.s_Motion.z = 1f; current.Use(); } else if (current.keyCode == (Event)SceneViewMotion.kFPSBack.keyCode) { sceneView.viewIsLockedToObject = false; SceneViewMotion.s_Motion.z = -1f; current.Use(); } else if (current.keyCode == (Event)SceneViewMotion.kFPSLeft.keyCode) { sceneView.viewIsLockedToObject = false; SceneViewMotion.s_Motion.x = -1f; current.Use(); } else if (current.keyCode == (Event)SceneViewMotion.kFPSRight.keyCode) { sceneView.viewIsLockedToObject = false; SceneViewMotion.s_Motion.x = 1f; current.Use(); } else if (current.keyCode == (Event)SceneViewMotion.kFPSUp.keyCode) { sceneView.viewIsLockedToObject = false; SceneViewMotion.s_Motion.y = 1f; current.Use(); } else if (current.keyCode == (Event)SceneViewMotion.kFPSDown.keyCode) { sceneView.viewIsLockedToObject = false; SceneViewMotion.s_Motion.y = -1f; current.Use(); } if (current.type == EventType.KeyDown || (double)motion.sqrMagnitude != 0.0) { return; } SceneViewMotion.s_FPSTiming.Begin(); }
public static void DoViewTool(SceneView view) { Event current = Event.current; int viewToolId = SceneViewMotion.s_ViewToolID; EventType typeForControl = current.GetTypeForControl(viewToolId); if ((bool)((Object)view) && Tools.s_LockedViewTool == ViewTool.FPS) { view.FixNegativeSize(); } switch (typeForControl) { case EventType.MouseDown: SceneViewMotion.HandleMouseDown(view, viewToolId, current.button); break; case EventType.MouseUp: SceneViewMotion.HandleMouseUp(view, viewToolId, current.button, current.clickCount); break; case EventType.MouseDrag: SceneViewMotion.HandleMouseDrag(view, viewToolId); break; case EventType.KeyDown: SceneViewMotion.HandleKeyDown(view); break; case EventType.KeyUp: SceneViewMotion.HandleKeyUp(); break; case EventType.ScrollWheel: SceneViewMotion.HandleScrollWheel(view, !current.alt); break; case EventType.Layout: Vector3 movementDirection = SceneViewMotion.GetMovementDirection(); if (GUIUtility.hotControl != viewToolId || (double)movementDirection.sqrMagnitude == 0.0) { break; } view.pivot = view.pivot + view.rotation * movementDirection; view.Repaint(); break; } }
private static void HandleMouseUp(SceneView view, int id, int button, int clickCount) { if (GUIUtility.hotControl == id) { SceneViewMotion.ResetDragState(); RaycastHit raycastHit; if (button == 2 && !SceneViewMotion.s_Dragged && SceneViewMotion.RaycastWorld(Event.current.mousePosition, out raycastHit)) { Vector3 b = view.pivot - view.rotation * Vector3.forward * view.cameraDistance; float newSize = view.size; if (!view.orthographic) { newSize = view.size * Vector3.Dot(raycastHit.point - b, view.rotation * Vector3.forward) / view.cameraDistance; } view.LookAt(raycastHit.point, view.rotation, newSize); } Event.current.Use(); } }
public static void ArrowKeys(SceneView sv) { Event current = Event.current; int controlID = GUIUtility.GetControlID(FocusType.Passive); if (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID) { if (!EditorGUI.actionKey) { EventType typeForControl = current.GetTypeForControl(controlID); if (typeForControl != EventType.KeyDown) { if (typeForControl != EventType.KeyUp) { if (typeForControl == EventType.Layout) { if (GUIUtility.hotControl == controlID) { Vector3 forward; if (!sv.m_Ortho.value) { forward = Camera.current.transform.forward + Camera.current.transform.up * 0.3f; forward.y = 0f; forward.Normalize(); } else { forward = Camera.current.transform.forward; } Vector3 movementDirection = SceneViewMotion.GetMovementDirection(); sv.LookAtDirect(sv.pivot + Quaternion.LookRotation(forward) * movementDirection, sv.rotation); if (SceneViewMotion.s_Motion.sqrMagnitude == 0f) { sv.pivot = sv.pivot; SceneViewMotion.s_FlySpeed = 0f; GUIUtility.hotControl = 0; } else { sv.Repaint(); } } } } else if (GUIUtility.hotControl == controlID) { switch (current.keyCode) { case KeyCode.UpArrow: case KeyCode.DownArrow: SceneViewMotion.s_Motion.z = 0f; SceneViewMotion.s_Motion.y = 0f; current.Use(); break; case KeyCode.RightArrow: case KeyCode.LeftArrow: SceneViewMotion.s_Motion.x = 0f; current.Use(); break; } } } else { switch (current.keyCode) { case KeyCode.UpArrow: sv.viewIsLockedToObject = false; if (sv.m_Ortho.value) { SceneViewMotion.s_Motion.y = 1f; } else { SceneViewMotion.s_Motion.z = 1f; } GUIUtility.hotControl = controlID; current.Use(); break; case KeyCode.DownArrow: sv.viewIsLockedToObject = false; if (sv.m_Ortho.value) { SceneViewMotion.s_Motion.y = -1f; } else { SceneViewMotion.s_Motion.z = -1f; } GUIUtility.hotControl = controlID; current.Use(); break; case KeyCode.RightArrow: sv.viewIsLockedToObject = false; SceneViewMotion.s_Motion.x = 1f; GUIUtility.hotControl = controlID; current.Use(); break; case KeyCode.LeftArrow: sv.viewIsLockedToObject = false; SceneViewMotion.s_Motion.x = -1f; GUIUtility.hotControl = controlID; current.Use(); break; } } } } }
private static void HandleMouseDrag(SceneView view, int id) { SceneViewMotion.s_CurrentState = SceneViewMotion.MotionState.kDragging; if (GUIUtility.hotControl == id) { Event current = Event.current; switch (Tools.s_LockedViewTool) { case ViewTool.Orbit: if (!view.in2DMode && !view.isRotationLocked) { SceneViewMotion.OrbitCameraBehavior(view); view.svRot.UpdateGizmoLabel(view, view.rotation * Vector3.forward, view.m_Ortho.target); } break; case ViewTool.Pan: { view.viewIsLockedToObject = false; view.FixNegativeSize(); Camera camera = view.camera; Vector3 vector = camera.WorldToScreenPoint(view.pivot); vector += new Vector3(-Event.current.delta.x, Event.current.delta.y, 0f); Vector3 vector2 = Camera.current.ScreenToWorldPoint(vector) - view.pivot; vector2 *= EditorGUIUtility.pixelsPerPoint; if (current.shift) { vector2 *= 4f; } view.pivot += vector2; break; } case ViewTool.Zoom: { float num = HandleUtility.niceMouseDeltaZoom * (float)((!current.shift) ? 3 : 9); if (view.orthographic) { view.size = Mathf.Max(0.0001f, view.size * (1f + num * 0.001f)); } else { SceneViewMotion.s_TotalMotion += num; if (SceneViewMotion.s_TotalMotion < 0f) { view.size = SceneViewMotion.s_StartZoom * (1f + SceneViewMotion.s_TotalMotion * 0.001f); } else { view.size += num * SceneViewMotion.s_ZoomSpeed * 0.003f; } } break; } case ViewTool.FPS: if (!view.in2DMode && !view.isRotationLocked) { if (!view.orthographic) { view.viewIsLockedToObject = false; Vector3 a = view.pivot - view.rotation * Vector3.forward * view.cameraDistance; Quaternion quaternion = view.rotation; quaternion = Quaternion.AngleAxis(current.delta.y * 0.003f * 57.29578f, quaternion * Vector3.right) * quaternion; quaternion = Quaternion.AngleAxis(current.delta.x * 0.003f * 57.29578f, Vector3.up) * quaternion; view.rotation = quaternion; view.pivot = a + quaternion * Vector3.forward * view.cameraDistance; } else { SceneViewMotion.OrbitCameraBehavior(view); } view.svRot.UpdateGizmoLabel(view, view.rotation * Vector3.forward, view.m_Ortho.target); } break; default: Debug.Log("Enum value Tools.s_LockViewTool not handled"); break; } current.Use(); } }
private static void HandleMouseDrag(SceneView view, int id) { SceneViewMotion.s_Dragged = true; if (GUIUtility.hotControl != id) { return; } Event current = Event.current; switch (Tools.s_LockedViewTool) { case ViewTool.Orbit: if (!view.in2DMode) { SceneViewMotion.OrbitCameraBehavior(view); view.svRot.UpdateGizmoLabel(view, view.rotation * Vector3.forward, view.m_Ortho.target); break; } break; case ViewTool.Pan: view.viewIsLockedToObject = false; view.FixNegativeSize(); Vector3 vector3_1 = Camera.current.ScreenToWorldPoint(view.camera.WorldToScreenPoint(view.pivot) + new Vector3(-Event.current.delta.x, Event.current.delta.y, 0.0f)) - view.pivot; if (current.shift) { vector3_1 *= 4f; } view.pivot += vector3_1; break; case ViewTool.Zoom: float num = HandleUtility.niceMouseDeltaZoom * (!current.shift ? 3f : 9f); if (view.orthographic) { view.size = Mathf.Max(0.0001f, view.size * (float)(1.0 + (double)num * (1.0 / 1000.0))); break; } SceneViewMotion.s_TotalMotion += num; view.size = (double)SceneViewMotion.s_TotalMotion >= 0.0 ? view.size + (float)((double)num * (double)SceneViewMotion.s_ZoomSpeed * (3.0 / 1000.0)) : SceneViewMotion.s_StartZoom * (float)(1.0 + (double)SceneViewMotion.s_TotalMotion * (1.0 / 1000.0)); break; case ViewTool.FPS: if (!view.in2DMode) { if (!view.orthographic) { view.viewIsLockedToObject = false; Vector3 vector3_2 = view.pivot - view.rotation * Vector3.forward * view.cameraDistance; Quaternion rotation = view.rotation; Quaternion quaternion1 = Quaternion.AngleAxis((float)((double)current.delta.y * (3.0 / 1000.0) * 57.2957801818848), rotation * Vector3.right) * rotation; Quaternion quaternion2 = Quaternion.AngleAxis((float)((double)current.delta.x * (3.0 / 1000.0) * 57.2957801818848), Vector3.up) * quaternion1; view.rotation = quaternion2; view.pivot = vector3_2 + quaternion2 * Vector3.forward * view.cameraDistance; } else { SceneViewMotion.OrbitCameraBehavior(view); } view.svRot.UpdateGizmoLabel(view, view.rotation * Vector3.forward, view.m_Ortho.target); break; } break; default: Debug.Log((object)"Enum value Tools.s_LockViewTool not handled"); break; } current.Use(); }