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 zannghast · Sep 26, 2014 at 09:07 AM · monodevelopreferencedependency

Is there a way to mimic the 'Find References' functionality of MonoDevelop?

We all know how useful MonoDevelop's 'Find References' feature is for certain scenarios where you'd want to quickly find all scripts and EXACT lines in the whole solution that reference or call a specific method/function.

I just want to get your ideas on how one could accomplish this in Unity. I need to create a tool that essentially provides the reverse of CollectDependencies (http://docs.unity3d.com/ScriptReference/EditorUtility.CollectDependencies.html), and yet, does so on a lower level (i.e. finding exact lines of code in the whole project that call the function).

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 zannghast · Sep 26, 2014 at 09:12 AM 0
Share

By the way, the closest solution I could find is probably this: http://wiki.unity3d.com/index.php/UnityAssetXrefs. That utility, however, doesn't allow me to specify which function I wanted to find references of. Only the class/script. It's close though...

1 Reply

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

Answer by Bunny83 · Sep 26, 2014 at 09:59 AM

Yes, it is possible, but you have to dive a bit deeper into reflection. I don't post a full working example here, just the basic steps you need:

  • AppDomain.CurrentDomain to get the current app domain

  • Then use GetAssemblies to get a list of all loaded assemblies. You might want to filter that list as you won't find references to your own classes / methods / fields in mscorlib.dll, UnityEngine.dll, ... and searching the whole appdomain would probably take hours :)

  • On the remaining assemblies you would call GetTypes to get a list of all classes defines in that assembly. So you end up with a huge list of System.Type references.

  • On each type you would call GetMethods to get all MethodInfos of all methods in those classes. Keep in mind to use the BindingFlags version if you also want to search private / static methods

  • The MethodInfo class (or to be more precise it's base class MethodBase) has a method called GetMethodBody which returns a MethodBody object

  • There are many "frameworks" to parse the IL code into OpCodes. This might also help

  • Once you have the OpCodes you can search the OpCode parameters / immediate values for a certain MethodInfo / FieldInfo.

That's all :D

Comment
Add comment · Show 4 · 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 vexe · Sep 26, 2014 at 10:08 AM 0
Share

Yep, pretty straight forward :D

avatar image zannghast · Sep 28, 2014 at 03:10 PM 0
Share

that is a pretty extensive answer Bunny83. Thanks! I will try this out asap and most probably will come back to this question to check your answer as the accepted one. thumbsup

avatar image zannghast · Sep 29, 2014 at 06:21 AM 0
Share

after reading stuff on .NET, IL, and Reflection, I cannot believe I made it all the way up to this point in my coding life where I have not yet (not even once) dived into all this which seems pretty straightforward and easy as vexe points out... I feel like a jackass, lol... well, something new to learn everyday!

avatar image Kiwasi · Sep 29, 2014 at 06:44 AM 1
Share

Wow. Impressive. It will be a long time before I call any code using reflection straightforward and easy. :)

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

26 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

Related Questions

using System.Security.Cryptography.Xml in Unity 0 Answers

A node in a childnode? 1 Answer

MonoDevelop not Interfacing with Unity 2 Answers

how to debug in monodevelop 1 Answer

There is no preferences option in MonoDevelop-Unity 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