Say you have a trivial prefab, "Box", which we'll say is nothing more than a standard meter cube.
1 - The prefab Box is in your Project panel
2 - Drag it to the Scene
3 - Obviously it now appears in the Hierarchy panel also, and probably selected and shown in Inspector
To be clear, game is NOT Play when you do this, you're only in ordinary Editor mode.
Is it possible to make a script (an "Editor script"?) so that,
when you do "1" and "2" above, (again this is in Editor mode, not during a game)
when 3 happens, we can affect the new Box item in the scene
So, simple example: we will set the Z position to "2" always, no matter where you drop it.
In short: Editor code so that every time you drag a prefab P to the scene, it sets the position z to 2.0.
Is this possible in Unity? I know nothing of "editor scripts".
It seems very obvious this should be possible.
Selection.activeGameObject
and lots of code. You need a way to distinguish between when the object is actually dragged to the hierarchy and when the object is rearranged in the Hierarchy. Both of these triggers one callback function. You would also need to implement saving and loading of variables since this is an Editor plugin and they will reset anytime you click "Play" button leading to a bugEditorApplication.hierarchyChanged
but it's also called when the object is re-arranged in the scene. Actually,Selection.activeGameObject
here is not unrelated because when you drag object from Project to Hierarchy tab, the object is automatically selected, therefore inSelection.activeGameObject
. It can be used withEditorApplication.hierarchyChanged