How do you get a list of project scripts at edit-time?

I have a custom class called MyCustomClass.

I would like to provide a UI selector in the editor so that the user can choose from one of their own classes that derives from MyCustomClass.

Either something similar to an ObjectField (which doesn’t work for this purpose) where a user can open up a selector that lists all the objects you specify, or, a dropdown menu that lists all the objects you specify.

Then when the user selects one, I can set a backing variable to the user’s choice, and store it on another class for later use at runtime.

My question is, how do I obtain a list of classes from within an editor script, both a CustomInspector, and an EditorWindow?

EditorGUILayout.ObjectField doesn’t seem to work. I get an “InvalidCastException” error, yet when I print the member I feed that function, and the returned result, both print as being of type MyCustomClass. So I think that is an editor bug. I also tried Object.FindObjectsOfTypeIncludingAssets however I see some strange behaviour with this, as follows:

// Returns all meshes.
Mesh[] meshes = (Mesh[])Object.FindObjectsOfTypeIncludingAssets( typeof( Mesh ) );

// Returns all shaders, including built in shaders.
Shaders[] shaders = (Shader[])Object.FindObjectsOfTypeIncludingAssets( typeof( Shader ) );
    
// Returns every single asset.
MyCustomClass[] myClasses = (MyCustomClass[])Object.FindObjectsOfTypeIncludingAssets( typeof( MyCustomClass) );

Any information and help appreciated, perhaps there is a solution I have not considered, and am approaching this the wrong way.

Hello, I managed to find a solution as follows - hope this helps if anyone has a similar task:

    public static MonoScript[] GetScriptAssetsOfType<T>()
    {
        MonoScript[] scripts = (MonoScript[])Object.FindObjectsOfTypeIncludingAssets( typeof( MonoScript ) );
        
        List<MonoScript> result = new List<MonoScript>();
        
        foreach( MonoScript m in scripts )
        {
            if( m.GetClass() != null && m.GetClass().IsSubclassOf( typeof( T ) ) )
            {
                result.Add( m );
            }
        }
        return result.ToArray();
    }

When I retrieve all methods from a single script, I use reflection to get a list of all methods:

Assembly []referencedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
for(int i = 0; i < referencedAssemblies.Length; ++i)
{
    System.Type type = referencedAssemblies*.GetType( scriptNameString );*

if( type != null )
{ // I want all the declared methods from the specific class.
System.Reflection.MethodInfo []methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
}
}
Maybe you can use some similar way to get out all classes from a single script.
Good luck!

Unity has made Object. FindObjectsOfTypeIncludingAssets obsolete and recommends you use Resources. FindObjectsOfTypeAll but this will not find all assets.

I have written a small piece of code that you can use in Editor only that takes a generic type and will return all objects in your project regardless of if they have been loaded yet.

public static List<T> FindAssetsByType<T>() where T : UnityEngine.Object
{
	List<T> assets = new List<T>();

	string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));

	for( int i = 0; i < guids.Length; i++ )
	{
		string assetPath = AssetDatabase.GUIDToAssetPath( guids *);*
  •   	T asset = AssetDatabase.LoadAssetAtPath<T>( assetPath );*
    
  •   	if( asset != null )*
    
  •   	{*
    
  •   		assets.Add(asset);*
    
  •   	}*
    
  •   }*
    
  •   return assets;*
    
  • }*

You can use the Apps Script dashboard to view and manage individual executions of Apps Script project functions. You can find a full log of recent executions by selecting the My Executions item in the left nav.

The My Executions panel shows by default a log of all previous and currently running executions for projects for which you are an owner, editor or viewer. This list can also include function executions in projects that you don’t have access to if they run on your behalf (for example, add-ons that you’ve installed and run). The execution list only shows the initial function that is called to start the execution. It does not show every function that was called during that execution.

You can control which type of execution is reported in the log using the filters at the top of the view. Each row of the log represents a single execution. The Start Time, Duration, and Status columns show the corresponding information about that execution.

The Function column shows the name of the function that initiated the execution. There is no name in this column if you don’t have access to the execution’s corresponding script project but it ran on your behalf.

The Type column shows what initiated the execution. Values include:

Add On. The execution originated from an add-on.
Execution API. The execution originated from an invocation of the Apps Script API.
Time Driven. The execution was caused by a time event.
Trigger. The execution originated from a trigger source.
Webapp. The execution originated from a deployed web app.
Editor. The execution originated from the Apps Script editor.,The Apps Script dashboard lists all the script projects that you can view or … The number of times a project has been “run” or executed.

The Apps Script dashboard lists all the script projects that you can view or edit. The left nav of the dashboard divides these projects into the following categories:

Starred Projects. Projects that you are monitoring.
My Projects. Projects for which you are an owner.
All Projects. Projects which you own or have view or edit permissions for.
Shared with me. Projects that you do not own but that have been shared with you.
Trash. Projects that you have removed from Google Drive.
The project lists show the project name, owner, and last modified date. The icons next to the project name indicate whether the project is a standalone project or a bound project.