Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jung-Lee · Jul 18, 2018 at 12:53 PM · unity 5editor-scripting

Create a dropdown with folder depth structure in Editor

I want to create a tool which will traverse as shown in below.

 Dropdown1 - {should have level 1 directories, on selection this should generate a dropdown2 with the Second level folders and files}

 Dropdown2 - {This will only get generate based on above parent selected value and will generate if there are any subfolders or files present in it.}

This should happen in Editor not in runtime.

and so on, this dynamic EditorGUILayout.PopUp generation need to happen until i reach a file in depth, If any intermediate Folder selection is been changed then respctive dropdown's should be updated.

I am not able to think of any solution, any leads/Hints will be helpful.

Regards, Jithendra.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pako · Jul 18, 2018 at 01:47 PM 0
Share

Just a clarification: folders are inside the "Project" pane showing all folders under the "Assets" folder. This is what you want to traverse at runtime? Or maybe you are looking at the "tree structure" in the "Hierarchy" pane, and you refer to that hierarchy as "folders"? Because these are not folders, they are GameObjects in the scene, presented as a tree structure in the Hierarchy pane.

avatar image Jung-Lee pako · Jul 19, 2018 at 04:48 AM 0
Share

Yeah something like in Project Pane but it should be populated as dropdowns, each level of directory may have mor than one folder so i want to display them in a dropdown so that user can easily traverse. I have achieved this solution in Windows Forms but not able to find a way to implement in Editor Scripts.

avatar image Bunny83 · Jul 19, 2018 at 07:02 AM 0
Share

Sorry but i can't really follow your description. I have no idea what the final thing should look like. A single drop down menu is a linear list of menu items and can optionally have sub menus, however you should keep the nesting of menu items small. Do you want a dropdown with submenus for the whole file structure? That would be extremely inefficient. Also keep in $$anonymous$$d that a folder could contain many (many) other folders or files. It's very impractical to show such lists as dropdowns. You see the problem when you try to show a dropdown for $$anonymous$$eyCode. $$anonymous$$ost the time the whole dropdown doesn't fit onto the screen.


Finally your question is confusing. You know that "EditorGUILayout.PopUp" is a pure editor feature which can not be used at runtime. Also that the asset folder and it's structure doesn't exist at runtime in a build. You should be more clear what you want to achieve and where (runtime or editor). $$anonymous$$aybe have some schemaric / drawing of what you want it to look like?

avatar image Jung-Lee Bunny83 · Jul 25, 2018 at 11:01 AM 0
Share

I have edited the question for better understanding, each level in the folder structure should depect by a dropdown in editor.

Please let me know if you have any questions further.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by stektpotet · Aug 04, 2018 at 03:53 PM

I'm not entirely sure if this is quite what you wanted, the EditorGUILayout.Popup function, I find is a bit limited, so I instead took use of GenericMenus. Looks mostly the same when used:

 #if UNITY_EDITOR
 using UnityEditor;
 using UnityEngine;
 using System.Linq;
 public class ProjectAssetDropdowns: ScriptableWizard
 {
     [MenuItem("Tools/Testing")]
     static void CreateWizard()
     {
         DisplayWizard<ProjectAssetDropDowns>("Testing...");
     }

     private int _selected = -1;
     public string SelectedDisplay
     {
         get
         {
             if(_selected < 0 || _selected >= paths.Length)
             {
                 return "NOTHING SELECTED";
             }
             return Selected.Split(new char[] { '/', '\\' }).Last();
         }
     }
     public string Selected
     {
         get
         {
             if (_selected < 0 || _selected >= paths.Length)
             {
                 return string.Empty;
             }
             return paths[_selected];
         }
     }

     string[] paths;
     private void OnFocus()
     {
         paths = AssetDatabase.GetAllAssetPaths();
     }

     protected override bool DrawWizardGUI()
     {
         if (GUILayout.Button(SelectedDisplay))
         {
             GenericMenu dropdown = new GenericMenu();
             for (int i = 0; i < paths.Length; i++)
             {
                 if (paths[i].StartsWith("Assets/"))
                 {
                     dropdown.AddItem(
 //Add the assetpath minus the "Asset/"-part
                         new GUIContent(paths[i].Remove(0, 7)),
 //show the currently selected item as selected
                         i == _selected, 
 //lambda to set the selected item to the one being clicked
                         selectedIndex => _selected = (int)selectedIndex, 
 //index of this menu item, passed on to the lambda when pressed.
                         i
                    );
                 }
             }
             dropdown.ShowAsContext(); //finally show the dropdown
         }
         if (_selected >= 0 && _selected < paths.Length)
         {
             Object selectedAsset = AssetDatabase.LoadAssetAtPath(Selected, typeof(Object));

             Texture t = AssetPreview.GetAssetPreview(selectedAsset);
             if(t != null)
                 GUI.DrawTexture(GUILayoutUtility.GetRect(200, 200), t);

         }
         //Do stuff with the selected item

         return (_selected >= 0 && _selected < paths.Length);
     }
 }
 #endif

Here's how it looks in the end: alt text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

186 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to stop reorderable list from passing Event value to the new element 1 Answer

Unable to load asset at path with unity tutorial code 1 Answer

Precalculate lighting by editor script 0 Answers

Hello I am new to unity 5.3 , While working over Creation of Beautiful Terrain with the help of https://www.youtube.com/watch?v=qdXT-BFz27k and While Entering into playmode I am getting following Error 0 Answers

Can't remove using Unity Editor, it is necessary for the development of the game. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges