Created
October 30, 2020 18:25
-
-
Save SiarheiPilat/4ed2c47a8d0882f266d676afd4b4fa48 to your computer and use it in GitHub Desktop.
Move a prefab instance to the bottom of the hierarchy whenever you drag and drop it to the scene.
This file contains 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
#if UNITY_EDITOR | |
using UnityEngine; | |
using UnityEditor; | |
[InitializeOnLoad] | |
public static class NewObjectBottomOfHierarchy | |
{ | |
static NewObjectBottomOfHierarchy() | |
{ | |
SceneView.duringSceneGui += PlaceDroppedObjectToTheBottom; | |
} | |
static void PlaceDroppedObjectToTheBottom(SceneView sceneView) | |
{ | |
if(Event.current.type == EventType.DragExited) | |
{ | |
if(Selection.gameObjects.Length > 0) | |
{ | |
// this checks out because it's only possible to drag and drop a single prefab to the scene at a time! | |
Selection.gameObjects[0].transform.SetAsLastSibling(); | |
} | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment