Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 Kashrlyyk · Aug 21, 2014 at 11:06 PM · mousedrag

Letting go of a dragged object

I have this code:

     if( new Rect(0, 0+ (cnt * BUTTONSIZE), BUTTONSIZE,BUTTONSIZE).Contains(e.mousePosition)) {
         if(e.clickCount == 2) { 
     //DO something 
                     }
     
         if(e.button == 0 && e.type == EventType.mouseDrag && !draggingItem){
                         draggingItem = true;
                         draggedItemIndex = cnt;
                         draggedItem = item;
                             Debug.Log ("Test drag");
                         }
     
                     if(e.type == EventType.mouseUp && draggingItem )
                         {
                             Debug.Log ("Dropped item");
     
                         }                
     }
 

The "Debug.Log("Dropped item");" is never printed to the console. So why is the "mouseUp" event never recognized? The dragging and the double click works.

Dragging the item and then doubleclicking prints "Dropped item" to the console but that is not how it should work.

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
0

Answer by Kashrlyyk · Aug 22, 2014 at 11:03 AM

It only detects the mouseUp event when I let the mouse button go while I am hovering over the Rect defined at the top.

EDIT: I want to drag the item from the inventory inside a "GUI.BeginScrollView" and drop it into a "GUI.SelectionGrid" outside the scrollview.

So I have added this to my code which is completely inside the "GUI.BeginScrollView" section:

  for(int cnt=0; cnt < _inventPlayer1W.Count; cnt++) {
 
                 EquipShortcut item = _inventPlayer1W[cnt]  as EquipShortcut;
     if( _inventPlayer1W[cnt] != null )  {
                     GUI.DrawTexture(new Rect(0, 0+ (cnt * BUTTONSIZE), BUTTONSIZE,BUTTONSIZE), _inventPlayer1W[cnt].GetIcon());
                     GUI.Box (new Rect(0+2+BUTTONSIZE, 0+ (cnt * BUTTONSIZE), 320,BUTTONSIZE), _inventPlayer1W[cnt].GetName(),GUI.skin.GetStyle("ToolTipHeading" ));
                     GUI.Label (new Rect(0+2+BUTTONSIZE, 0+ (cnt * BUTTONSIZE), 30,30), c1.Inventory.GetWeaponCount(item.ID).ToString());
                 }
 
 
     if(new Rect(0, 0+(cnt * BUTTONSIZE), BUTTONSIZE, BUTTONSIZE).Contains(e.mousePosition)) {
                     Debug.Log ("Slots in inventory"+ " " + slotRect.x.ToString()+ " "+ slotRect.min.ToString() +" " + slotRect.max.ToString() + " " + slotRect.y.ToString());
                     slotRect = new Rect(0, 0+ (cnt * BUTTONSIZE), BUTTONSIZE,BUTTONSIZE);
 
     if( slotRect.Contains(e.mousePosition)) {
         if(e.type == EventType.mouseDown && e.button == 1){
                             c1.Inventory.Remove(c1.Inventory.GetEquipment(item.ID, ItemDropType.Weapon),1, true, true);
                             if(c1.Inventory.GetWeaponCount(item.ID) == 0){
                                 _inventPlayer1W.Remove(_inventPlayer1W[cnt]);
                                 //_inventPlayer1W = c1.Inventory.GetContent(c1, false, false, true, false);
                             }
                         }
                         
     if(e.clickCount == 2) { //e.type == EventType.mouseDown && e.button == 0 &&
                             if(c1.Inventory.GetEquipment(item.ID, ItemDropType.Weapon).CanEquip(c1)) {
                                 c1.Equipment.Equip(-1, item, c1.Inventory, false);
                                 if(c1.Inventory.GetWeaponCount(item.ID) == 0){
                                     _inventPlayer1W.Remove(_inventPlayer1W[cnt]);
                                 }
                             }
                         }
                         
                         if(e.button == 0 && e.type == EventType.mouseDrag && !draggingItem){
                             draggingItem = true;
                             draggedItemIndex = cnt;
                             draggedItem = item;
     Debug.Log ("Test drag" + draggedItemIndex.ToString() + " " + draggedItem.GetName());
                         }
                         
                         if(e.button == 0 && e.type == EventType.MouseUp && draggingItem )// && player2GridPos.Contains(e.mousePosition))
                         {
                             Debug.Log ("Dropped item");
                             //_inventPlayer2W.Add(_inventPlayer1W[cnt]);
                             //_inventPlayer1W.Remove(_inventPlayer1W[cnt]);
                             draggingItem = false;
                             draggedItem = null;
                         }                
                     }
 
     } else if(new Rect(25-WIDTHOFFSET, 25-HEIGHTOFFSET-200, 192, 270).Contains(e.mousePosition)){
 Debug.Log ("This should work"+ draggingItem.ToString() + " " + slotRect.x.ToString()+ " "+ slotRect.min.ToString() +" " + slotRect.max.ToString() + " " + slotRect.y.ToString());
                     for(int y1 = 0; y1 < 3; y1++) {
                         for(int x1 = 0; x1 < 2; x1++) {
                             slotRect = new Rect(25+ (x1 * 95)-WIDTHOFFSET,25 + (y1 * 89)-HEIGHTOFFSET-200, 97, 87);
                                                             
                                 /*if(e.button == 0 && e.type == EventType.mouseDrag && !draggingItem){
                                     draggingItem = true;
                                     draggedItemIndex = cnt;
                                     draggedItem = item;
                                     Debug.Log ("Test drag" + draggedItemIndex.ToString() + " " + draggedItem.GetName());
                                 }*/
                                 
                                 if(e.button == 0 && e.type == EventType.MouseUp && draggingItem )// && player2GridPos.Contains(e.mousePosition))
                                 {
                                     Debug.Log ("Dropped item");
                                     
                                     draggingItem = false;
                                     draggedItem = null;
                                 }                
                             }
                         }
                     }
                 }


"new Rect(25-WIDTHOFFSET, 25-HEIGHTOFFSET-200, 192, 270)" that is the position and size of the selectionGrid seen from inside the scrollview and when I hover over it the "This should work...." line is printed to the console but I still can't drop the item on that rect.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How To Make GUI/Dragable Object - Att: Video 3 Answers

Mouse drag get angle 1 Answer

Mouse drag gameobject 0 Answers

Input.GetMouseButtonUp not detected after drag 1 Answer

Camera and Mouse Movement 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges