Skip to content

Instantly share code, notes, and snippets.

@hariedo
Created September 1, 2025 03:11
Show Gist options
  • Save hariedo/4d2c2fe85a23bbc442156085e60f357c to your computer and use it in GitHub Desktop.
Save hariedo/4d2c2fe85a23bbc442156085e60f357c to your computer and use it in GitHub Desktop.
// SelectionOutlinePreference
using System;
using System.Reflection;
using UnityEngine;
using UnityEditor;
// Put in a folder called 'Editor' anywhere inside project Assets folder.
// Combines ideas based on forum posts:
// https://discussions.unity.com/t/dsiable-selection-outlines-on-object/869598/2
// https://discussions.unity.com/t/editor-how-to-add-checkmarks-to-menuitems/114525/6
[InitializeOnLoad]
public static class SelectionOutlinePreference
{
private const string MENUITEM_NAME =
"Edit/Selection/Show Selection Outline";
private static bool enabled = true;
static SelectionOutlinePreference()
{
SelectionOutlinePreference.enabled =
EditorPrefs.GetBool(MENUITEM_NAME, true);
EditorApplication.delayCall += () =>
{
PerformAction(SelectionOutlinePreference.enabled);
};
}
[MenuItem(MENUITEM_NAME)]
private static void ToggleAction()
{
PerformAction(!enabled);
}
public static void PerformAction(bool enable)
{
Menu.SetChecked(MENUITEM_NAME, enable);
EditorPrefs.SetBool(MENUITEM_NAME, enable);
SelectionOutlinePreference.enabled = enable;
ToggleSelectionGizmo(enable);
}
private static void ToggleSelectionGizmo(bool enable)
{
Type AnnotationUtility =
Type.GetType("UnityEditor.AnnotationUtility, UnityEditor");
var ShowOutlineOption = AnnotationUtility.GetProperty(
"showSelectionOutline",
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Static);
ShowOutlineOption.SetValue(null, enable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment