The example below disables the Hierarchy and Object Inspector panels for WebGL builds.
public class NjConsoleSettingsBuildProcessor : IPreprocessBuildWithReport
{
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var settings = ConsoleSettings.Get();
var platform = report.summary.platform;
settings.inPlayerObjectInspector = platform != BuildTarget.WebGL;
settings.inPlayerHierarchyPanel = platform != BuildTarget.WebGL;
}
}
β οΈ Note: In production builds, a determined attacker could still enable console features via memory hacking.
For best security, use compile defineNJCONSOLE_DISABLE
to strip out the console completely. See next section for more info.
#if !NJCONSOLE_DISABLE
.#if !NJCONSOLE_DISABLE
.#if !NJCONSOLE_DISABLE
to ensure itβs fully stripped from production builds.NJCONSOLE_DISABLE
in Player Settings > Scripting Define Symbols.ConsoleEditorSettings.AddDefineSymbolToDisableConsole()
Example below disables NjConsole in release builds, and attempts to reenable it after the build.
using Ninjadini.Console.Editor;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
public class NjConsoleBuildDisableProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder => -1000;
public void OnPreprocessBuild(BuildReport report)
{
var isDevelopmentBuild = (report.summary.options & BuildOptions.Development) != 0;
if (isDevelopmentBuild) return;
// ^ Have your own conditional logic here. In this example, we only disable NjConsole in release (non-debug) builds.
ConsoleEditorSettings.AddDefineSymbolToDisableConsole();
}
public void OnPostprocessBuild(BuildReport report)
{
// Reenable NjConsole.
// Unfortunately, if the build failed, this code will not execute and you'll need to manually turn it on from Project Settings > NjConsole > Disable.
// This code is not needed if you are using a build box where you revert the changes after build.
ConsoleEditorSettings.RemoveDefineSymbolAndEnableConsole();
}
}