Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 firestorm713q · Sep 03, 2015 at 05:41 PM · c#uiguieventsystemevents

ScrollRect and IDragHandler on touch devices

I'm working on an iOS game, and I'm having issues with figuring out how to handle a particular situation. On the left side of the screen is my "Card List" Which is essentially an inventory list, populated according to the Scrollable List tutorial from Unity. In the center is a set of Equipment Slots, basically UI Panels with a grid layout that snaps a card to that slot. (from this tutorial) I want the user to be able to both scroll the list on the left by swiping up/down, and able to drag cards onto their equipment slots by long pressing the card, and then dragging it over.


Relevant Code: CardDragHandler.cs (attached to card, only relevant functions shown):

     public void OnBeginDrag (PointerEventData eventData)
     {
         //transform.SetParent (PositionsPanel);
         ObjectBeingDragged = gameObject;
         startPosition = transform.position;
         GetComponent<CanvasGroup> ().blocksRaycasts = false;
         startParent = transform.parent;
         PressBegan = Time.time;
         DragStartPosition = eventData.position;
     }
 
 
     public void OnDrag (PointerEventData eventData)
     {
         PressTime = Time.time - PressBegan;
         float distance = Vector3.Distance (DragStartPosition, eventData.position);
         if(PressTime>LongPressTime && distance<1)
             transform.position = eventData.position;
     }
 
     public void OnEndDrag (PointerEventData eventData)
     {
         ObjectBeingDragged = null;
         GetComponent<CanvasGroup>().blocksRaycasts = true;
         //transform.SetParent (CardContentPanel);
         if (transform.parent == startParent) {
             transform.position = startPosition;
         }
     }


CardDropHandler.cs (attached to slot):

 public void OnDrop (PointerEventData eventData)
     {
         CardDragHandler.ObjectBeingDragged.transform.SetParent (transform);
     }


How do I keep the draghandler from overriding the scrollRect? How do I kick it out of the drag event entirely so that it scrolls instead?

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 nieyoub23 · Dec 02, 2017 at 05:33 AM

Did you figure it out? I am trying to do the same thing but cant get them to work together.

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 nieyoub23 · Dec 02, 2017 at 07:31 PM 0
Share

I changed my Canvas to overlay and it worked

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UI: Mouse events not working 1 Answer

Ui Elements and Unity Events 1 Answer

How do I trigger OnSelect() via the ISelectHandler in my class? 1 Answer

UnityEngine.EventSystems.. Trying to figure it out .js 1 Answer

How to set passed param to event trigger callback in script? 1 Answer


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