Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 dustxx · Jan 10, 2015 at 04:44 PM · editor-scriptingprojectfolder

Can you change the current folder of the project view via script?

Seems like a simple enough question. If I have a folder for prefabs like "Assets/Resources/Prefabs/Area/Tiles" and a folder for textures like "Assets/Textures/Area/Tiles" I'd like to make an editor script that can jump back and forth between them. I know how to do all that stuff except for actually changing the project view's folder. I looked at the ProjectWindowUtil class and there doesn't seem to be anything helpful there, so if there's not a way to do this is there any way I can request it? Thanks.

Comment
Add comment · Show 1
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 Xarbrough · Dec 10, 2017 at 12:58 AM 0
Share

I know this is old and answered, but I came across it when searching for how to change the project browser's folder from code. The provided answer relies on knowing specific assets within the folder, which I didn't like, so I used reflection and Unity's internal methods to show the folder. See my thread here, if anyone is interested: https://forum.unity.com/threads/tutorial-how-to-to-show-specific-folder-content-in-the-project-window-via-editor-scripting.508247/

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by dustxx · Jan 26, 2015 at 07:04 AM

I solved my own problem. You can't directly change the project view, but if you change the "Selection.activeObject" to an asset in a folder, the project view will jump to the folder in which that asset is stored. In my case, I simply used the path of the current "Selection.activeObject" to replace the needed parts to find the asset I wanted and set that to the selection. Simple enough!

 //Draw the 'Switch Selection Between Tile and Texture' tool
     private void DrawSwitchSelectionBetweenTileAndTextureTool()
     {
         if ( GUILayout.Button("Switch Selection Between Tile and Texture") )
         {
             Object mirroredAsset = GetMirroringTileOrTexture(Selection.activeObject);
             if ( mirroredAsset != null ) { Selection.activeObject = mirroredAsset; }
             else { CancelOperation("Could not find mirroring asset"); }
         }
     }
 
     //Get the Tile mirroring a texture or the texture mirroring a tile
     private Object GetMirroringTileOrTexture(Object asset)
     {
         string activeSelectionPath = AssetDatabase.GetAssetPath(asset);
         string mirroredActiveSelectionPath = null;
         
         //Convert the path
         if ( activeSelectionPath.Contains("Resources/Prefabs/Overworld") )
         {
             mirroredActiveSelectionPath = new StringBuilder(activeSelectionPath).Replace("Resources/Prefabs/Overworld", "Textures").Replace(Constants.PREFAB_EXTENSION, Constants.PNG_EXTENSION).ToString();
         }
         else if ( activeSelectionPath.Contains("Textures") )
         {
             mirroredActiveSelectionPath = new StringBuilder(activeSelectionPath).Replace("Textures", "Resources/Prefabs/Overworld").Replace(Constants.PNG_EXTENSION, Constants.PREFAB_EXTENSION).ToString();
         }
         
         return AssetDatabase.LoadAssetAtPath(mirroredActiveSelectionPath, typeof(Object));
     }
Comment
Add comment · Show 1 · 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
avatar image tanoshimi · Jan 26, 2015 at 07:04 AM 1
Share

Plus 1 for co$$anonymous$$g back and providing the solution :)

avatar image
0

Answer by Hauthorn · Jul 31, 2019 at 12:36 AM

For people looking for exactly what is needed to do this,

 EditorUtility.FocusProjectWindow();
 Selection.activeObject = myObject;
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Project backup save 3 Answers

Moving from Project to Hierarchy 3 Answers

Which folders in a Unity project are critical folders? 4 Answers

Unity Folder way too big - bigger than inside Files 1 Answer

Custom editor script for folders? 1 Answer


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