• 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
0
Question by Sprakle · May 17, 2014 at 11:45 PM · guieditordraganddrop

OnGUI() not called during DragAndDrop

I have a custom editor window that needs some drag and drop functionality. For some reason, the window stops repainting once dragging starts. Since OnGUI stops, dragging can never complete.

What the test window looks like:

alt text

Test Code:

     public class DragTest : EditorWindow
     {
         [MenuItem("Window/Drag Test")]
         internal static void Init()
         {
             GetWindow(typeof(DragTest), false, "Drag Test");
         }
 
         private List<Draggable> draggables;
 
         public DragTest()
         {
             draggables = new List<Draggable>();
 
             for (int i = 0; i < 10; i++)
                 draggables.Add(new Draggable(i));
         }
 
         private void OnGUI()
         {
             Debug.Log("On GUI");
 
             // update each draggable
             foreach (Draggable draggable in draggables)
                 draggable.Draw();
         }
     }
 
     public class Draggable
     {
 
         private int number;
 
         public Draggable(int number)
         {
             this.number = number;
         }
 
         public void Draw()
         {
             EditorGUILayout.LabelField("Draggable Object");
 
             // get area that can be clicked on
             Rect dropArea = GUILayoutUtility.GetLastRect();
 
             Event currentEvent = Event.current;
 
             // ignore if mouse is outside the area
             if (!dropArea.Contains(currentEvent.mousePosition))
                 return;
 
             switch (Event.current.type)
             {
                 case EventType.MouseDown:
                     Debug.Log("Clicked on " + number);
 
                     // no more OnGUI messages after this
                     DragAndDrop.PrepareStartDrag();
 
                     currentEvent.Use();
                     break;
 
                 case EventType.MouseDrag:
                     Debug.Log("Dragging" + number);
                     DragAndDrop.StartDrag("Title");
 
                     currentEvent.Use();
                     break;
 
                 case EventType.DragUpdated:
 
                     Debug.Log("Drag updated on " + number);
 
                     currentEvent.Use();
                     break;
             }
         }
     }


Comment
Add comment · Show 2
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 Sprakle · May 18, 2014 at 05:08 PM 0
Share

I am basing this off of code found here: http://forum.unity3d.com/threads/223242-Drag-and-Drop-in-the-editor-Explanation

avatar image Sprakle · May 18, 2014 at 08:15 PM 0
Share

Very strange, the problem seems to go away if I have a second unrelated editor script updating at the same time. At least it works.

I wont mark this as answered until I'm sure it stays this way.

0 Replies

· Add your reply
  • Sort: 

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

DragAndDrop EditorGUILayout.Box ? 1 Answer

Are there any Editor fields which are Drag and Drop? 0 Answers

uGUI - aligning to the bottom of another element 0 Answers

How do I toggle the active state of a canvas UI object 0 Answers

Drawing Editor Inspector GUI based on selected/current prefab (CustomPropertyDrawer) 2 Answers

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