Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Am i stupid? Create an editor focus function

Discussion in 'Editor & General Support' started by Sandler, Jul 16, 2019.

  1. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    241
    I may have this done wrong for years, but why isnt there a focus this gameobject function inside the editor?

    Im often working on gameobjects in big scenes, and i want to select one sprite on screen.
    Since i can remember im clicking myself crazy:
    The sprite on screen i wanna select -> click, click, click, click, click, click -> F*** one to far, ctrl + z

    Am i doing this wrong or is this just bad usability?^^
     
  2. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    241
    I mean this probably cost me weeks.
    And a highlight my sprite on selection would be neat too.

    The focus function should only make the currently foces object be selectable via clicks.
     
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    There is.
    Select an object and press F to focus the camera on it.
     
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    So yea, there is a "Frame Selected" option (default hotkey 'F') which zooms the SceneView camera to the selected GameObject, but you are probably asking a different question.

    Selection in the SceneView is cumbersome, that is true, and it would be my feedback towards Unity as well, to improve the selection mechanism. Currently, it cycles through all objects under the mouse cursor, which is really annoying in large scenes. Instead, I would propose some sort of selection menu like in Photoshop layers, where you context click and then it shows you a dropdown of all objects under the mouse.

    Highlights around selected objects are already available. If you expand the SceneView's Gizmos dropdown you can enable "Selection Outline".

    Additionally, I would call your idea "focus mode" or "selection lock". You can already lock the inspector of the currently selection object with the lock icon at the top right of the inspector. This still allows you to select other objects, but the inspector stays the same.

    I also agree that a focus mode can make sense for very specific setups, but the question would be if this is something everybody needs.

    For the meantime, you can prototype this yourself with an editor window like this:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class FocusModeWindow : EditorWindow
    5. {
    6.     [MenuItem("Window/Focus Mode")]
    7.     public static void ShowWindow()
    8.     {
    9.         GetWindow<FocusModeWindow>("Focus Mode");
    10.     }
    11.  
    12.     private GameObject focusedGameObject;
    13.  
    14.     private void OnSelectionChange()
    15.     {
    16.         EditorApplication.delayCall += () =>
    17.         {
    18.             if (focusedGameObject != null)
    19.             {
    20.                 Selection.activeGameObject = focusedGameObject;
    21.             }
    22.         };
    23.     }
    24.  
    25.     private void OnGUI()
    26.     {
    27.         focusedGameObject = EditorGUILayout.ObjectField(
    28.             "Focused GameObject", focusedGameObject, typeof(GameObject), allowSceneObjects: true) as GameObject;
    29.     }
    30. }
    This window allows you to pick a GameObject and resets the selection to this object whenever is changes. It would be more elegant to block the selection change, but I didn't investigate whether this is possible with the current API, however it's a start and something to try out.
     
  5. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Well oops, I completely misunderstood this question.
     
  6. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    241
    Thanks for the replays.
    I may prototype something and post it back here.

    I think the bigger problem are the canvas objects which get selected even when not visible (CanvasGroup alpha = 0).
    Those should be excluded from the click events per option. I keep them active so the canvas draw gets triggered at the beginning of the scene.
    If you use canvas overlay mode it basicaly is a gigantic screen which you have to click through all the time.

    So if people are using canvas for their gui, they probably are facing that problem, but are used to it