Last active
December 23, 2025 19:37
-
-
Save hariedo/4d2c2fe85a23bbc442156085e60f357c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SelectionOutlinePreference.cs | |
| // | |
| using System; | |
| using System.Reflection; | |
| using UnityEngine; | |
| using UnityEditor; | |
| // Adds menu items to toggle the Unity Editor tab's outlining of the selected objects. | |
| // Helpful when trying to preview the look of particle systems or other alpha-edged objects. | |
| // | |
| // 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