Search Unity

Feedback Ability to Remap Pan Shortcut to "Alt + Shift + Left Click" instead of "Middle Click"

Discussion in 'Editor & General Support' started by Noble-Woods, Sep 10, 2020.

  1. Noble-Woods

    Noble-Woods

    Joined:
    May 24, 2013
    Posts:
    6
    I recently switch from Maya to Blender, and I love that I can easily pan around with "Alt+Shift+Left Click" instead of the standard "Middle Click" pan. Many computer mice have awkward middle click buttons, and I've found that the "Alt+Shift+Left Click" shortcut in Blender is far easier for me to use.

    Currently "Shortcuts" in Unity only allow keyboard input and there is no "3D Viewport/Pan" command to replace. It'd be awesome if Unity could add a "3D Viewport/Pan" command and allow mouse input to be combined with keys in Shortcuts.

    I created an AutoHotkey script that maps "Alt+Shift+Left Click" to a Middle Click hold, but I can't get it to feel as smooth as Unity's Middle Click pan, which is why I made this feature request. If you want to run the script for yourselves, save the attached text file as a .ahk and run it with AutoHotkey. Thanks!
     

    Attached Files:

  2. Noble-Woods

    Noble-Woods

    Joined:
    May 24, 2013
    Posts:
    6
  3. setikek

    setikek

    Joined:
    Nov 12, 2023
    Posts:
    3
    bump. still looking for a way to rebind controls for pan and zoom
     
  4. setikek

    setikek

    Joined:
    Nov 12, 2023
    Posts:
    3
    alright, I did some refinement with chatgpt and got a working script for the controls I wanted (pan: shift + alt + left click, zoom: ctrl + alt + left click. just like in Blender). if someone wants to use their own controls they can either dive into the code or ask chatgpt to change it. sensitivity is adjusted with the '5f' and '.002f' values

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [InitializeOnLoad]
    5. public class SceneViewControls : MonoBehaviour
    6. {
    7.     private static bool isPanning;
    8.     private static bool isZooming;
    9.     private static Vector2 lastMousePosition;
    10.  
    11.     static SceneViewControls()
    12.     {
    13.         SceneView.duringSceneGui += OnSceneGUI;
    14.     }
    15.  
    16.     private static void OnSceneGUI(SceneView sceneView)
    17.     {
    18.         Event e = Event.current;
    19.  
    20.         switch (e.type)
    21.         {
    22.             case EventType.MouseDown:
    23.                 if (e.button == 0 && e.shift && e.alt) // Shift + Alt + Left Click for panning
    24.                 {
    25.                     isPanning = true;
    26.                     lastMousePosition = e.mousePosition;
    27.                     e.Use();
    28.                     SceneView.RepaintAll(); // Repaint to update cursor
    29.                 }
    30.                 else if (e.button == 0 && e.control && e.alt) // Ctrl + Alt + Left Click for zooming
    31.                 {
    32.                     isZooming = true;
    33.                     lastMousePosition = e.mousePosition;
    34.                     e.Use();
    35.                 }
    36.                 break;
    37.  
    38.             case EventType.MouseUp:
    39.                 if (e.button == 0)
    40.                 {
    41.                     if (isPanning)
    42.                     {
    43.                         isPanning = false;
    44.                         e.Use();
    45.                         SceneView.RepaintAll(); // Repaint to update cursor
    46.                     }
    47.                     else if (isZooming)
    48.                     {
    49.                         isZooming = false;
    50.                         e.Use();
    51.                     }
    52.                 }
    53.                 break;
    54.  
    55.             case EventType.MouseDrag:
    56.                 if (isPanning)
    57.                 {
    58.                     Vector2 delta = e.mousePosition - lastMousePosition;
    59.                     delta /= sceneView.size * 5f;
    60.                     Vector3 move = new Vector3(-delta.x, delta.y, 0); // Adjust for both X and Y
    61.                     sceneView.pivot += sceneView.rotation * move;
    62.                     lastMousePosition = e.mousePosition;
    63.                     e.Use();
    64.                 }
    65.                 else if (isZooming)
    66.                 {
    67.                     float zoomDelta = e.delta.y * .002f; // Reverse the zoom direction
    68.                     sceneView.size *= Mathf.Exp(zoomDelta);
    69.                     lastMousePosition = e.mousePosition;
    70.                     e.Use();
    71.                 }
    72.                 break;
    73.         }
    74.     }
    75. }