SpaceMadness / lunar-unity-console

High-performance Unity iOS/Android logger built with native platform UI
https://www.assetstore.unity3d.com/en/#!/content/43800
Other
839 stars 114 forks source link

Toggling Lunar Console from build preprocessor #169

Closed Nezz closed 4 years ago

Nezz commented 4 years ago

We'd like to use a build preprocessor to toggle Lunar Console in our builds. We tried calling LunarConsolePluginEditorHelper.SetLunarConsoleEnabled, but we noticed that the libraries are still included in iOS and Android builds.

Enabling and disabling the plugin seems to require the editor scripts to recompile first. Would it be possible to make it take effect immediately, so we can toggle Lunar Console from a preprocessor?

weeeBox commented 4 years ago

Would be able to describe your preprocessor approach in more detail? I'm not sure, I'm fully understand it.

Nezz commented 4 years ago

Sure, here's an example:

public class BuildEnvironmentPreprocessor : IPreprocessBuildWithReport
{
    public int callbackOrder => 1;

    public void OnPreprocessBuild(BuildReport report)
    {
        var releaseBuild = Environment.GetCommandLineArgs().Any(arg => arg == "--release");
    LunarConsolePluginInternal.LunarConsolePluginEditorHelper.SetLunarConsoleEnabled(!releaseBuild);
    }
}
weeeBox commented 4 years ago

As far as I understand, this approach is for command line builds, right?

weeeBox commented 4 years ago

If you can run a command line before the build process you can do this:

<UNITY_BIN_PATH> -projectpath <PROJECT_PATH> -quit -batchmode -executeMethod LunarConsoleEditorInternal.Installer.DisablePlugin

For more information see this guide

Nezz commented 4 years ago

Yes, this is for command line build. We run builds in a single Unity execution to save time since Unity has a large launch time overhead. That's why we are asking for a solution that works without recompiling the project.

weeeBox commented 4 years ago

Another option is to update Project/Assets/LunarConsole/Scripts/LunarConsole.cs file manually: you need to replace #define LUNAR_CONSOLE_ENABLED with #define LUNAR_CONSOLE_DISABLED.

For more details see: disable_lunar_console.sh

Nezz commented 4 years ago

I'll take a stab at implementing this and submit a PR. Should be reasonably easy to do.

weeeBox commented 4 years ago

Hey @Nezz,

Did you have a chance to look at it?

Nezz commented 4 years ago

Yes, I'd have to make LunarConsoleConfig.consoleEnabled non-readonly and move LunarConsolePluginEditorHelper.SetLunarConsoleEnabled to the Editor assembly so it can call AndroidPlugin.SetEnabled. Does this sound good on a high level? I can submit a PR early next week.

weeeBox commented 4 years ago

Should be fine for now. I'm planning to add Package Manger support and move away from preprocessor defines in 2.0.0 release.