Skip to content

Conversation

@brogan89
Copy link
Contributor

@brogan89 brogan89 commented Feb 9, 2024

I needed a way to remove all commands that I've added as my users were using scene.load etc and wasn't working with my custom scene management. I couldn't find a way to loop over all the commands that didn't require reflection.

The delegate I added was mainly to log to console any command that had run so when I got bug reports in Sentry I could see what they were trying to do.

Below is an example use case for these features.

    private void Start()
    {
        DebugLogConsole.OnCommandExecuted += OnCommandExecuted;
        RemoveStockCommands();
    }

    private static void OnCommandExecuted(string command, object[] parameters)
    {
        if (parameters?.Length > 0)
            Debug.Log($"Command executed '{command}' with parameters: {string.Join(", ", parameters)}");
        else
            Debug.Log($"Command executed: {command}");
    }

    private static void RemoveStockCommands()
    {
        // need to copy as can cause enumeration exceptions
        var comamnds = new List<ConsoleMethodInfo>(DebugLogConsole.GetAllCommands());
        foreach (var m in comamnds)
        {
            if (!m.command.StartsWith('/'))
                DebugLogConsole.RemoveCommand(m.command);
        }
    }

@yasirkula
Copy link
Owner

Thank you! I've removed the XML comments because the member names were explanatory enough and added an actual null check before the event invocation because Unity 5.6 doesn't support the ?.Invoke syntax (I'm still supporting that version 🙃).

BTW, in the next release, I'll remove all commands except help from the plugin. You're right that the built-in commands should be opt-in, not opt-out.

@yasirkula yasirkula merged commit 55a7455 into yasirkula:master Feb 18, 2024
@brogan89
Copy link
Contributor Author

Sounds good! Thanks

yasirkula added a commit that referenced this pull request Feb 18, 2024
…s better to have these commands opt-in rather than opt-out. Built-in commands can be reactivated by adding IDB_ENABLE_HELPER_COMMANDS compiler directive in Player Settings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants