Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shortcut to Unpack and Unpack Completely

Discussion in 'Editor & General Support' started by theforgot3n1, Jan 29, 2022.

  1. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    205
    I can't find any shortcuts to these in the Shortcut manager. Anyone knows if shortcuts can be created or found somehow?
     
  2. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    205
    Regardless of whether there exists a shortcut (seems like there is none), I have made a script to work for me.


    Code (CSharp):
    1. public class EditorUnpack : Editor
    2. {
    3.     [MenuItem("Shortcuts/Unpack")]
    4.     static void Unpack()
    5.     {
    6.         Unpack(PrefabUnpackMode.OutermostRoot);
    7.     }
    8.     [MenuItem("Shortcuts/UnpackCompletely")]
    9.     static void UnpackCompletely()
    10.     {
    11.         Unpack(PrefabUnpackMode.Completely);
    12.     }
    13.     static void Unpack(PrefabUnpackMode mode)
    14.     {
    15.         foreach (Transform transform in Selection.transforms)
    16.         {
    17.             RectTransform t = transform as RectTransform;
    18.  
    19.             if (PrefabUtility.GetPrefabAssetType(transform.gameObject) != PrefabAssetType.Regular)
    20.             {
    21.                 continue;
    22.             }
    23.             else
    24.             {
    25.                 PrefabUtility.UnpackPrefabInstance(transform.gameObject, mode, InteractionMode.UserAction);
    26.             }
    27.         }
    28.     }
    29. }
    This adds a menu item Shortcuts with the Unpack and UnpackCompletely options. You can add a shortcut to if you want with the shortcut manager or a default directly in the editor script.
     
    sadpeperoni likes this.