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
1
Question by Bocaj · Sep 17, 2013 at 11:48 PM · hierarchysearch

hierarchy "ref:" search, but in script

I want this functionality: alt text in script form. Does This exist?


You can search for all scene references of an asset with that handy find window: ex. "ref:sounds/mysound.wav" will find all references to that sound in the scene and set the seleciton.

I want this same functionality (setting the selection) except I want to be able to do it from script: ex. FindReferences("ref:sounds/mysound.wav"); //sets Selection to all scene references of the passed in asset path.

Does this exist? If not, how can I get this (specifically for sound references preferably)?

Thanks!

hierarchysearch.jpg (11.7 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jamora · Sep 18, 2013 at 12:54 PM

It is possible, but you will probably need to do it yourself.

Things you'll need:

  • Reflection

  • EditorWindow/Custom Editor/Static Editor Script

  • AssetDatabase.LoadAssetAtPath

Things you might need:

  • AssetProcessor.OnPostProcessAllAssets

  • EditorApplication.searchChanged

You'll need a search field first. You can hook into the hierarchy search bar with EditorApplication.searchChanged. I didn't find any way to modify the result set, So it might be best to make your own search in an EditorWindow and display the results there.

I think the best way to loop through only the script files is to maintain a list of all script-assets in the project somewhere by creating an AssetPostProcessor that keeps track of all changes to the assets. This is the only way I found to efficiently find all script files in the project. Then you just need to do some parsing to get the script files that contain a declaration for an AudioClip, and simply FindObjectsOfType(typeof(FoundType)) multiple times. If this is not exactly what you need, you might have to use reflection.

When going the reflection route, first I would check if the search string contains the prefix for any special implementation you want (ref:). then if the given string actually refers to an existing asset. If it does, then we'll need all MonoBehaviours in the scene. Those can be found with FindObjectsOfType(typeof(MonoBehaviour)). Finally, you only (...) need to use reflection on each of those objects to find out any declared AudioClip field and check if it references the given asset.

Note: for some reason I always got two callbacks for the OnSearchChanged. You'll have to come up a way to dismiss the other if this also happens to you.

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
avatar image
0

Answer by gjf · Sep 18, 2013 at 02:39 PM

you'd probably be doing it with this - doubt you'd need to resort to reflection...

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 Jamora · Sep 18, 2013 at 07:49 PM 0
Share

Hmm, yes, possibly. $$anonymous$$aybe I understood the question wrong.

I understood the question to be such, that he wanted all the scripts that referenced whatever asset he put in the search box. For this he'll need to read all variables in all scripts and check what they reference.

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

16 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Locate asset in hierarchy 1 Answer

How to refer to objects, scripts, textures in Assets in C#? 0 Answers

How do I force a GameObject with children to collapse and expand in the hierarchy view? 1 Answer

Finding objects with TextMeshPro component. 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