Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Alex Brest · Apr 27, 2015 at 03:57 PM · dragscrollpointrect

How to change ScrollRect draging point?

Hi,

Basically what i want to do is a menu - much like the android main menu and the iphone homescreen. I have been struggling with this one for about a 5 hours now, so help will be much appreciated.

I have a panel "A" with scrollrect script on it. Inside it I have two more panels "B" and "C" (let's call them pages); Panels "B" and "C" have a GridLayoutGroup scripts that holds a number of elements - lets call them Icons.

Now, each Icon (element in panels B or C) have a script attached called "Dragable". It basically makes them move with the mouse on drag (while draging an icon, it sets it position to the position of the mouse).

Everything so far works great. But now I'm trying to add the ability to change pages (panels B and C) with swiping on the screen). Obviously if i just swipe the screen I start moving the icon my finger has landed on (except if I touch where there is no icon, then pages swipe correctly). To escape this I added a check - if i hold my finger on the icon for 1 second - then I set a flag "isDragged" and move it with the pointer. If I don't wait that 1 second, the flag isDragged is false, and then I do this:

  public void OnDrag (PointerEventData eventData) {
     if (!isDraged) {
       eventData.pointerDrag = transform.parent.parent.gameObject;
       return;
     }
     this.transform.position = eventData.position;
   }


Basically if isDragged is false, I change the receiver of the dragging - to the scrollrect. This also works somewhat fine - the only problem, and this is where I need your help - is that no matter where on screen I click, the draging point (like the point where i hold the scrollrect) is where i last clicked on the scrollrect.

What I mean is, if I click and drag whitout doing anything else first, the scrolrect content moves so my mouse is pointing in the middle of it. But if I click on any other place on the content before that (where no icon is in the way) then when I do a new drag, the whole content jumps so my mouse is pointing in the location i clicked earlier.

I feel like there is some variable "PlaceWhereMouseClicked" that is holding the coordinates of where the dragging is coming from. What I want to do is change it - so the draging comes from where my drag started, not where i cleicked earlier.

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
1
Best Answer

Answer by Alex Brest · Apr 28, 2015 at 08:31 AM

For anyone else, who finds himself in this situation:

What I finaly did is this:

In the three methods: OnBeginDrag, OnDrag and OnEndDrag I called the appropriate method of the scrollRect. This way the draging started on the appropriate place, and works the way I wanted it to.

Basically on the icon OnDrag method i did this:

 public void OnDrag (PointerEventData eventData) {
     if (!isDraged) {
         transform.parent.parent.OnDrag(eventData);
         return;
     }
 }

The same goes with the other two methods, and it works wonderfully.

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

Drag on Scroll Rect Non Proportional 0 Answers

NGUI: Draggable Camera and Scroll Panel 0 Answers

Nested Scroll Views: How can I pass drag control from an inner scroll view to its outer scroll view? 2 Answers

ScrollRect scrollbar drag being overridden and stuttering to top 0 Answers

Touchscript drag constraints 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