Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Focus folder in Project Window

Discussion in 'Extensions & OnGUI' started by F-R-O-S-T-Y, Sep 23, 2018.

  1. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    144
    Hey,

    Using editor code I would like to focus a certain folder in the Project window.
    I know how to create editor buttons, menu items etc but I have not found a way to focus a folder in project window. I have focused assets, which take me to a certain folder. But if a folder is empty is there a way to focus it?

    There should be a way because the Favorites system seems to use that.

    Any ideas?
    Thanks!
     
  2. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    144
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    847
    hi @F-R-O-S-T-Y

    I'm not sure how you would completely do it...

    This is from the forums modified by me, I have no idea of the origin. Just have it in my notes.

    Feels bit hacky, but at least it selects the folder - empty or not.

    However, it doesn't navigate into that folder, like you would double click it in Project view.

    This is just a demo (works from MB), GameObjects has item that you can click to navigate to folder Assets/Test.

    Code (CSharp):
    1.      [MenuItem("GameObject/TEST - SelectPath")]
    2.     static void SelectPath()
    3.     {
    4.         Debug.Log("SelectPath");
    5.  
    6.         string path =  "Assets/Test";
    7.  
    8.         UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
    9.  
    10.         Selection.activeObject = obj;
    11.  
    12.         EditorGUIUtility.PingObject(obj);
    13.     }
     
    F-R-O-S-T-Y likes this.
  4. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    144
    Thank you!

    I modified it a little bit. It is also important to call
    EditorUtility.FocusProjectWindow();
    before
    Selection.activeObject
    . I did not need to call
    EditorGUIUtility.PingObject(obj);


    Final code:
    Code (CSharp):
    1. EditorUtility.FocusProjectWindow();
    2.  
    3. Object obj = AssetDatabase.LoadAssetAtPath<Object>("Assets/Art/Models");
    4.  
    5. Selection.activeObject = obj;

    Thanks again! :)
     
    eses likes this.
  5. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    144
    Okay, never mind. While it does focus, for some reason when I add a new folder path to focus (using editor buttons), I have to click the editor button twice. With first click it takes me to one of the previous folders I focused (but I think the selection is correct), and with the second click the correct folder is focused in the project view (project view navigates to the correct path).

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class MenuItems {
    5.     [MenuItem("Favourites/Trees")]
    6.     private static void SelectFolder()
    7.     {
    8.         EditorUtility.FocusProjectWindow();
    9.  
    10.         Object obj = AssetDatabase.LoadAssetAtPath<Object>("Assets/Scripts/Player/Okay");
    11.  
    12.         Selection.activeObject = obj;
    13.     }
    14. }