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 justindz · Dec 03, 2016 at 07:41 AM · android2dmobiletoucheventsystem

OnPointerExit Issue w/ Radial Menu on Android

Greetings! In my mobile game, I connect to my game server to get a list of X characters and then once they are loaded, I instantiate them into my scene. Each of the characters has a radial menu of actions they can take that activates when you touch and hold. When you release, the menu goes away. While the menu is displaying, you can move your touch onto one of the menu options and release, which will choose that option. I have implemented the radial menu based on the following YouTube tutorial: https://www.youtube.com/watch?v=WzQdc2rAdZc -- the only thing I've added is code to take the selected action, which is not covered in the tutorial.

Everything works perfect in the Unity Editor. However, when I run it on my Android device, I run into a "small" problem. When I release on a menu item, the action never occurs. After thorough debugging, it looks like the issue is that the OnPointerExit handler which is used to deselect the button gets called when I lift my finger (remove the touch) and not just when I move my touch off of the button. So, basically, choosing a menu option is acting the same as deselecting it.

Here's the code:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 using System.Collections;
 
 public class RadialButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
     
     public Image circle;
     public Image icon;
     public string title;
     public Interactable.InteractableAction action;
     public RadialMenu myMenu;
     public float speed = 8f;
 
     Color defaultColor;
 
     public void Anim() {
         StartCoroutine (AnimateButtonIn ());
     }
 
     IEnumerator AnimateButtonIn() {
         transform.localScale = Vector3.zero;
         float timer = 0f;
         while (timer < (1 / speed)) {
             timer += Time.deltaTime;
             transform.localScale = Vector3.one * timer * speed;
             yield return null;
         }
         transform.localScale = Vector3.one;
     }
 
     public void OnPointerEnter (PointerEventData eventData)
     {
         myMenu.selected = this;
         defaultColor = circle.color;
         circle.color = Color.white;
     }
 
     public void OnPointerExit (PointerEventData eventData)
     {
         myMenu.selected = null;
         circle.color = defaultColor;
     }
 }

I have tried to implemented a separate touch system using preprocessor directives, but that has been a colossal failure. Any elegant solution to this? Is it possible on touch ended to prevent the on pointer exit handler from processing temporarily or something cheeky?

Comment
Add comment · Show 1
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 hexagonius · Dec 03, 2016 at 08:15 AM 0
Share

$$anonymous$$aybe using IPointerUpHandler ins$$anonymous$$d of or in addition to IPointerExitHandler works.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by justindz · Dec 11, 2016 at 09:17 AM

Unfortunately, IPointerUpHandler did nothing (quite literally). I think it requires a collider, possibly. The documentation is pretty sparse. I found an elegant solution, however:

 public void OnPointerExit (PointerEventData eventData)
     {
         if (Input.touchSupported) {
             if (Input.touches [0].phase == TouchPhase.Ended) {
                 myMenu.selected = this;
             } else {
                 myMenu.selected = null;
             }
         } else {
             myMenu.selected = null;
         }
         circle.color = defaultColor;
     }

Basically, we check if we're on a touch system and if the finger has been lifted to set the action. If we exit for any reason other than the finger lifting, we deselect. On a non-touch system, we always deselect, because the exit handler only gets called when we mouse off and not when we release the mouse. In all cases, we reset the button color.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to destroy object by touch? 2 Answers

Avoid touch input when pressing the "Pause" button 1 Answer

Scaling Script? 1 Answer

Placing a Rect and detecting a Touch/Tap 1 Answer

How to detect screen touching more frequently than fps. 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