Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How can you list all classes inside a namespace (such as UnityEngine) and every message method that

Discussion in 'General Discussion' started by TheRealRan, Nov 3, 2020.

  1. TheRealRan

    TheRealRan

    Joined:
    Jun 3, 2019
    Posts:
    18
    I was able to list all methods from a given class by following this link: https://answers.unity.com/questions/657436/how-to-list-all-the-properties-and-methods-from-th.html

    Though, I now need to get a list of every class a namespace has (such as every class from UnityEngine), which would be the list on the left: https://docs.unity3d.com/ScriptReference/AccelerationEvent.html (every class in the 'Classes' tab)

    Furthermore, I want to know the 'Message Methods" found in a class. The methods from the first link seem to only be public and static methods, and even without flags I do not receive the 'Awake', 'Start' and so one methods, found here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.html

    Is there anything that allows us to receive a list of any of these?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,324
    As far as I'm aware, "message methods" are simply methods whose name and signature match predefined pattern.
    I.e. they are not interafaces/virtual methods and so on. Instead unity looks them up by name, and then calls them when needed.

    So you'd need to go through documentation, write down names, and check if methods with such names are present within a class.
     
    MadeFromPolygons likes this.
  3. TheRealRan

    TheRealRan

    Joined:
    Jun 3, 2019
    Posts:
    18
    That's unfortunate, but at least I've found out how to get all the namespace classes: https://stackoverflow.com/questions/949246/how-can-i-get-all-classes-within-a-namespace

    Though that didn't seem to work for me with unity namespaces so I had to use this one instead:

    Code (CSharp):
    1. System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
    2.  
    3. Assembly unityEngine;
    4.  
    5. assemblies.ForEachItem(assembly =>
    6. {
    7.     if (assembly.FullName == "UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
    8.     {
    9.         unityEngine = assembly;
    10.                    
    11.         foreach (Type type in unityEngine.GetTypes())
    12.         {
    13.             Debug.Log(type.Name);
    14.         }
    15.     }
    16. });
    It will be a little bit helpful but not as helpful as having the message methods as well, unfortunatelly.
     
    MadeFromPolygons likes this.