stillwwater / command_terminal

Unity Command Terminal: In-Game Console
MIT License
446 stars 60 forks source link

Static methods not called if asset is in the /Plugins/ folder #2

Closed Saucy closed 5 months ago

Saucy commented 6 years ago

Hello!

I'm having trouble having static methods appear in the help-command, or being able to run at all if I have Command Terminal-folder in the /Plugins/ folder. Command Terminal works if it is outside the /Plugins/ folder.

My code:

using CommandTerminal;

public static class DebugTestCommand {
  [RegisterCommand(Help = "Outputs message")]
  static void CommandHello (CommandArg[] args) {
    Terminal.Log("Hello world!");
  }
}
stillwwater commented 6 years ago

Hi!

The Plugins folder compiles to a separate assembly. Right now the RegisterCommand attribute only works in the main assembly (source).

Try registering the command manually using Terminal.Shell.AddCommand.

I'll look into supporting separate assemblies.

JimmyCushnie commented 6 years ago

I've fixed this issue in my fork of Command Terminal. @stillwwater, if you want to do this it's very simple. On line 35 of CommandShell.cs, do this:

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
                foreach (var type in assembly.GetTypes()) {

instead of this:

foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) {