• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by BugKiller · Jun 17, 2015 at 07:35 PM · editorprefabhierarchydetectdrop

Detect on Editor Mode drop prefab to the hierarchy

Hello,

I created one level design tool to create levels and I want to extend one feature. I have one feature that Adds an enemy wave to the current level, the game designer clicks "Add wave" button, it opens a panel (OpenFilePanel) to select the wave prefab and then in my editor script I load and instantiate the prefab as a child of the array object and add it to the correct wave array.

The new feature is to drag and drop the prefab from the "Project Window" to the array object on the "Hierarchy Window" and automatically add it to the array as I did before with the button + OpenFilePanel. I searched a lot for this feature from Unity but didn't find anything..

The game designer can do this by dragging the wave prefab to the hierarchy as a child of the array object but he has to switch to "Debug Mode" to add/drag manually the wave to the array and I want to skip this second process on the Debug mode.

The problem is that I need to identify when one prefab is dropped on the scene to check his parent and add it from the editor script to the array.

Another thing I would like to do, if I can detect the drag and drop operation, is to switch the order of the elements on the prefab. Currently I have two buttons on my editor script for each wave on the array to "move up" and "move down" on the array order but I also would like to do this when the game designer changes the order of the wave objects on the hierarchy. If I can detect a drop I can check the order of the objects on the hierarchy and fix it on the array.

There is a way to do almost this as I want, that is to have a button "Update waves" that checks the child objects of the array on the hierarchy and update the array, but still there will be a button for the game designer to press...

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by winxalex · Oct 28, 2015 at 05:26 PM

This might give u an idea

Register callback handler

     EditorApplication.hierarchyWindowChanged -= OnHierarchyChanged;        
                 EditorApplication.hierarchyWindowChanged += OnHierarchyChanged;
             
 //Callback handler:
         private static void OnHierarchyChanged ()
         {

 if(Selection.activeGameObject!=null && PrefabUtility.GetPrefabType(Selection.activeGameObject)==PrefabType.PrefabInstance)
             Debug.Log (Selection.activeGameObject);


[1]: http://docs.unity3d.com/ScriptReference/EditorApplication-hierarchyWindowChanged.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JeromeJ · Mar 11, 2018 at 03:42 PM 0
Share

How to easily distinguish between a mere re-ordering of an existing object in the scene VS a prefab has just been dropped in the scene now.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Text Labels For Prefabs in Hierarchy Turn Pink 2 Answers

Breaking a prefab connection 7 Answers

How to properly edit prefabs with child elements? 1 Answer

Get all items from hierarchy? 2 Answers

assign a transform from the hierarchy to a prefab or script 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges