Author Topic: Avoid Click same time  (Read 13714 times)

neufoctobre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Avoid Click same time
« on: January 05, 2016, 09:14:53 AM »
Hello,

1. May be my question will be stupid but I wonder how to avoid fast click or click at same time. My problem is, I have a button 1 animation telling a buttton 2 to move out of screen, during this short animation I'm able to click on the animated button 2 and that is a problem, I have this problem for all my buttons. The only solution I found is to active a collider above all other for the entire screend during the animation but I still can click the button if I click enough fast..

2. In a same way, can I say to UIPlayAnimation to don't do anything if an object is enable. For example like above, I have a button 1 animation who enable a disabled button 2 which is out of screen and when the animation is done the button is on screen, If I clicked again on button 1 the animation begin again, I want to avoid that.

Thanks in advance !

jcbadboy

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Avoid Click same time
« Reply #1 on: January 05, 2016, 03:12:58 PM »
Friend, you could do this by many ways. I can tell you the way i did.

Any button pressed verify if some tweener is playing.

void ButtonPressed()
{
   if (any)
      return;
   else
      Do();
}


I can´t tell you the best way to know if any tweener is playing, my solution is not elegant, so i will not show you for now.
I sought for some static method or property in NGUI, but I do not found.
Perhaps somebody can show us how to do this. Anybody?  ::)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Avoid Click same time
« Reply #2 on: January 06, 2016, 11:50:07 PM »
A tweener is playing when it's enabled. It automatically disables itself when it finishes.

jcbadboy

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Avoid Click same time
« Reply #3 on: January 07, 2016, 12:57:48 PM »
Yes, thanks ArenMook.

But, would be cool if we could know if any tweener is playing.

I can do a findcomponent in scene and ask if any tweener is enabled. but it cost a lot.

In my solution here I create a list of all tweener playing. When each one stop, they leave the list.

If the list is greater then zero, a tweener still playing, and I do not accept inputs from any button.

My solution is bizarre, i know. Cuz, first, was needed to change NGUI to do that. Second, mantaining this list here cost more memory and more time of the frame.

Would be better if UITweener class had a static list, where each one tweener started add it self in. And, internally, remove it self from when finished.
This list, or a property knowing this list, would be accessed statically from every where. So, you can know now if any tweener is playing.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Avoid Click same time
« Reply #4 on: January 07, 2016, 01:23:46 PM »
If you need something like that then add a custom script that will do just that -- add itself to a static list. Attach it alongside the tweens you are interested in.

Remember, NGUI also adds tweens for things like button color animations for example. You don't want everything.

jcbadboy

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Avoid Click same time
« Reply #5 on: January 07, 2016, 03:23:25 PM »
Thanks for the reply. it can be easily made.

On my project, to bypass the tweens I don´t care I made UIPlaytween class generate the list of tweens of same group. Also, on each tween, UIPlaytween register a method on OnFinished to remove it from that list.
The list is static, so i can look into it and make my decisions about other tweens.

Could be possible NGUI maintain a static list of teens playing and a property read only?

Something like this:

    static List<UITweener> UITweeners;

    public static void AddUITweener(UITweener tweener)
    {
        if (UITweeners == null )
            UITweeners = new List<UITweener>();

        UITweeners.Add(tweener);
    }

    public static void RemoveUITweener(UITweener tweener)
    {
        if (UITweeners == null)
            return;

        UITweeners.Remove(tweener);
    }

    public static bool IsAnimating()
    {
        if (UITweeners != null && UITweeners.Count > 0)
            return true;

        return false;
    }



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Avoid Click same time
« Reply #6 on: January 09, 2016, 10:34:12 AM »
It really isn't something that belongs in the UI system... It's game specific code. You can even add to a custom static list as you play a tween and remove it in its OnFinished function - it would be 1 line of code each.

jcbadboy

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Avoid Click same time
« Reply #7 on: January 11, 2016, 08:08:50 AM »
ArenMook, thanks for the reply.

i understand the concern about not put game things on ui system, but, on my project i don't play tweens, i only play UIPlay Tween, because theres is a lot of tweeners being playing behind it, not only two or three. My game screens are complex and multiple objects are animated at same time. So i dont tryed to control each tweener, even for put each one in a custom list.

So, I  needed to change uiplaytween, so uiplaytween controls the custom list. Because all the tweeners will be children of it.  :o

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Avoid Click same time
« Reply #8 on: January 11, 2016, 05:33:32 PM »
So what's preventing you from attaching this script beside the tweens you are interested in?
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. [RequireComponent(typeof(UITweener))]
  5. public class CustomTracker : MonoBehaviour
  6. {
  7.     static public List<UITweener> list = new List<UITweener>();
  8.     UITweener mTween;
  9.     void OnEnable () { mTween = GetComponent<UITweener>(); list.Add(mTween); }
  10.     void OnDisable() { list.Remove(mTween); }
  11. }
  12.  

jcbadboy

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Avoid Click same time
« Reply #9 on: January 12, 2016, 05:15:39 PM »
ArenMook thanks for your time and effort.

Yes, would be very good. I understood the first time you brought it up. Thank you!