• Bugs
  • [Unity] Drag and Drop to Instantiate

Does not work in Unity 5.5f3.

Related Discussions
...

I'll check it out.


If you have the latest runtime, for now, uncomment these lines: spine-runtimes/SkeletonDataAssetInspector.cs at master
That will give you a button to instantiate, as an alternative.


Drag and Drop seems to be working in Unity 5.5.0f3
Just created a new project, imported the latest spine-unity.unitypackage. Instantiated Spineboy.

Oh, no. You can't drag into the Hierarchy. The UnityEditor API doesn't seem to expose that.

You have to drag it into Scene View.
See this topic. There's a gif. [New Feature] Drag and Drop to instantiate

If you've seen other plugins do otherwise, or know where that is, do let us know and we can try to add it.

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);

Hi see also drop menu appearing completely off. https://www.dropbox.com/s/wj4jsp6li8fqqbf/dropmenu.mp4?dl=0


Seems like this menu problem is connected to multiple monitor setup.

Thanks for reporting that! We'll take a look and fix it soon.
This seems like a potential fix for multi-monitor.
http://answers.unity3d.com/questions/829071/get-mouse-position-in-editor-based-on-screen-coord.html


foriero :
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);

That callback doesn't seem to be usable for this purpose. I tried handling it with just a method that says Debug.Log("hello");
Dragging and dropping a SkeletonDataAsset or any other asset into the hierarchy in an empty area or under or between existing GameObjects doesn't seem to cause the callback to be fired.

using UnityEditor;
 using UnityEngine;
 using System.Collections.Generic;
 // makes sure that the static constructor is always called in the editor.
 [InitializeOnLoad]
 public class ComponentXCreator : Editor
 {
     static ComponentXCreator ()
     {
         // Adds a callback for when the hierarchy window processes GUI events
         // for every GameObject in the heirarchy.
         EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemCallback;
     }
 
 static void HierarchyWindowItemCallback(int pID, Rect pRect)
 {
     // happens when an acceptable item is released over the GUI window
     if (Event.current.type == EventType.DragPerform)
     {
         // get all the drag and drop information ready for processing.
         DragAndDrop.AcceptDrag();
         // used to emulate selection of new objects.
         var selectedObjects = new List<GameObject>();
         // run through each object that was dragged in.
         foreach (var objectRef in DragAndDrop.objectReferences)
         {
             // if the object is the particular asset type...
             if (objectRef is AssetX)
             {
                 // we create a new GameObject using the asset's name.
                 var gameObject = new GameObject(objectRef.name);
                 // we attach component X, associated with asset X.
                 var componentX = gameObject.AddComponent<ComponentX>();
                 // we place asset X within component X.
                 componentX.assetX = objectRef as AssetX;
                 // add to the list of selected objects.
                 selectedObjects.Add(gameObject);
             }
         }
         // we didn't drag any assets of type AssetX, so do nothing.
         if (selectedObjects.Count == 0) return;
         // emulate selection of newly created objects.
         Selection.objects = selectedObjects.ToArray();
 
         // make sure this call is the only one that processes the event.
         Event.current.Use();
     }
 }
 }

Works?

Yes seems like osx related dual monitor setup. But I was asking about that drag and drop script to hierarchy. I feel like the last one will work for you, right?

1 年 后

Not quite. It doesn't work when you drag it to an empty area like you can with Sprites and Prefabs. The resulting behavior is confusing if you just use it as is because it doesn't visually reflect it's supposed to do, nor expose what it's visually showing. (ie, highlights items or between items in the hierarchy)

Hacked a different way. Still testing.
I feel like Unity really doesn't want us doing this.