yasirkula / UnityIngameDebugConsole

A uGUI based console to see debug messages and execute commands during gameplay in Unity
MIT License
2.11k stars 221 forks source link

Only Assembly-CSharp is supported for the ConsoleMethodAttribute #39

Closed billw2012 closed 3 years ago

billw2012 commented 3 years ago

I use asmdefs for my game code, and so ConsoleMethodAttribute will not work. I changed your code to this and it works for me now:

foreach( var (method, attr) in AppDomain.CurrentDomain
    .GetAssemblies()
    .Where(a => !a.IsDynamic)
    .SelectMany(a => a.GetExportedTypes())
    .SelectMany(t => t.GetMethods( BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly ))
    .Select(m => (method: m, attr: m.GetCustomAttributes( typeof( ConsoleMethodAttribute ), false ).OfType<ConsoleMethodAttribute>().FirstOrDefault()))
    .Where(m => m.attr != null)
    )
{
    AddCommand( attr.Command, attr.Description, method );
}
yasirkula commented 3 years ago

Yes I'm aware of this limitation. That's why I like the DebugLogConsole.AddCommand functions. I'm inspecting only Assembly-CSharp purely for performance reasons. I fear including all assemblies in the search would take significantly more time and it would be unpreferable for users who aren't interested in custom commands.

billw2012 commented 3 years ago

A few things you could consider:

billw2012 commented 3 years ago

I tried to optimize the assembly list and could only get it down to ~25ms by excluding modules based on name prefix (which isn't bullet proof), and company attribute value. This still left 14 out of 120 assemblies, all my plugins and game code. Its a shame that module attributes are so inconsistently applied. e.g. having one generated automatically for each asmdef module would help in this case, but there isn't any such thing.

yasirkula commented 3 years ago

I've omitted most of the built-in assemblies from the search. Hopefully it will be pretty fast.