Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
3
Question by JamesJLinden · Apr 01, 2015 at 06:17 PM · uiiphonebuttonsscrollviewdragging

Recreating iPhone Home Screen in Unity

I am trying to recreate a UI menu that has functionality similar to the iPhone's home screen:

  • If a user drags anywhere on the menu (including on a button), it should drag the whole page left/right depending on the user's drag.

  • If a user clicks and holds motionlessly on a single button, it "dislodges" the button so that it can be dragged around.

alt text

I have all of my functionality working, including the dislodge. The one exception being that I'm running into a situation where I'm not sure how to transfer the drag message consumed by a button onto the backing scroll container if the user has not clicked long enough on a single button to "dislodge" it.

That is, I place my finger onto a button and drag (with the intention of dragging the entire page) but I'm not sure how to redirect the same drag message onto the ScrollRect of my backing container. Instead, my button consumes the OnDrag message and the page is not scrolled. The only method of scrolling the page is simply dragging on an empty part of the container where there is no button.

alt text

I'm using UI elements from Unity's 4.6 UI:

  • I am using a ScrollRect to represent the backing container with all of my buttons

  • I'm using a GridLayout to resize and pad my buttons

  • I'm using a regular UI.Button class on each of my buttons

  • I'm using the following EventSystem interfaces to catch and handle input for my buttons: IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler

Is there something already built into Unity that can allow me to transfer/redirect the drag message from one GameObject to another while the drag is still in process? Or do I need to rebuild parts of the UI from scratch to support this?

ios-home-screen-resized.jpg (34.3 kB)
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
11
Best Answer

Answer by GibTreaty · Apr 08, 2015 at 11:51 PM

One way that works is to store the PointerEventData and use ExecuteEvents to end the drag on the current object and start the drag on the new target object.

 public GameObject other;
 float time = 0;
 
 PointerEventData data;
 
 void Update() {
     if(time > 0) {
         time = Mathf.Max(time - Time.deltaTime, 0);
 
         if(time == 0) {
             ExecuteEvents.Execute<IEndDragHandler>(gameObject, data, ExecuteEvents.endDragHandler);
             data.pointerDrag = other;
             ExecuteEvents.Execute<IBeginDragHandler>(other, data, ExecuteEvents.beginDragHandler);
         }
     }
 }
Comment
Add comment · Show 4 · 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 JamesJLinden · Apr 09, 2015 at 01:09 AM 1
Share

@GibTreaty--Really appreciate the response, I'll give your solution a look and I'll get back to you.

avatar image JamesJLinden · Apr 28, 2015 at 08:58 PM 1
Share

This does exactly what I needed it to do. Thank you GibTreaty.

avatar image Drekey · Jul 29, 2015 at 09:50 PM 0
Share

If anyone stumble upon this and it still doesn't work for them, make sure you are using the correct PointerEventData object.

avatar image Aike · Sep 23, 2016 at 02:00 PM 0
Share

This answer is gold !! Thank you guys :D

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

21 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 avatar image

Related Questions

Selection problem of Toggles/Buttons in a draggable ScrollRect 0 Answers

can you duplicate unity 4.6 Buttons 0 Answers

OnGUI/iPhone - cannot touch TWO+ buttons at the same time...? 3 Answers

[Old GUI] Buttons on Top not responding correctly on iOS 0 Answers

scrollview on iphone acts weird 3 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