Search Unity

How to add a folder to a selection?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Andres-Fernandez, Sep 11, 2015.

  1. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    Hi there,
    I would like to know if there's a way to add a folder from the Project panel to a selection. I know that I can add whatever object I want to the selection by using Selection.object (and also there are many answers like this one and this other one). What I haven't been able to find is a way to "select a folder" from the Project panel. Any ideas?
    The reason is that I need to adapt some AssetBundle generation code that relays on selecting folders in the Project panel and I want to emulate that with code. Is it possible?
    Thanks.
     
  2. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    So, yeah, I managed to make it work just by getting a reference to the asset path as if it was a simple object.

    Code (CSharp):
    1. UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath("Assets/MyFolder", typeof(UnityEngine.Object));
    2. UnityEngine.Object[] selection = new UnityEngine.Object[1];
    3. selection[0] = obj;
    4. Selection.objects = selection;
    Not pretty (as I get some warnings when creating the assetbundle) but it works.
     
    IgorSimovic and MaximilianPs like this.
  3. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    AssetDatabase.OpenAsset(folderAssetObject);

    Or
    Selection.activeObject = folderAssetObject;
    EditorGUIUtility.PingObject(folderAssetObject);