Author Topic: Query if a tween is finished/played?  (Read 5929 times)

juggernate

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Query if a tween is finished/played?
« on: January 21, 2013, 12:58:39 PM »
Is there a way to query if a UITweener(TweenPosition, TweenAlpha etc) is in it's finished, or played state? I see Sample(float factor, bool isFinished), but it doesn't return isFinished. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Query if a tween is finished/played?
« Reply #1 on: January 21, 2013, 03:41:32 PM »
Why not have a callback instead? UITweener.onFinished will be executed when the tween completes -- no need to query anything.

juggernate

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: Query if a tween is finished/played?
« Reply #2 on: January 21, 2013, 03:53:38 PM »
Thanks for the reponse.
I have set up a mode switching system that triggers many tweens based on which mode gets broadcast, (I'm getting so many tweens it makes sense to do this instead of hooking up a bunch of individual tween triggers) I need to know the finished state of tweens when I'm using multiple tweenGroups on a few objects so I can reverse the correct tweens. I'll experiment with onFinished. Thanks!

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Query if a tween is finished/played?
« Reply #3 on: January 21, 2013, 05:04:50 PM »
Here is a (large) snippet from a class I have that does what you are asking for.  The functions you are interested in are "pushPanes" and "popPanes".  "pushPanes" takes some message information so you know when all the weening is done.


  1.    void TweenPositionPushOutFinished()
  2.    {
  3.       mTransitionPushOutCount--;
  4.       if(mTransitionPushOutCount > 0 || mPaneStack.Count == 0)
  5.          return;
  6.      
  7.       mPaneStack.Add(mNextPanelSet);
  8.       foreach(GameObject pPane in mNextPanelSet)
  9.       {
  10.          pPane.SendMessage("TansitionInStarted", SendMessageOptions.DontRequireReceiver);
  11.          
  12.          TweenPosition pTweenPosition = pPane.GetComponent<TweenPosition>();
  13.          if(pTweenPosition != null)
  14.          {
  15.             pTweenPosition.Play(true);
  16.             pTweenPosition.eventReceiver = gameObject;
  17.             pTweenPosition.callWhenFinished = "TweenPositionPopInFinished";
  18.             mTransitionPopInCount++;
  19.          }
  20.       }
  21.       mNextPanelSet = null;
  22.    }
  23.    
  24.    void TweenPositionPopInFinished()
  25.    {
  26.       mTransitionPopInCount--;
  27.       if(mTransitionPopInCount > 0)
  28.          return;
  29.      
  30.       List<GameObject> pLastSet = mPaneStack[mPaneStack.Count - 1];
  31.       foreach(GameObject pPane in pLastSet)
  32.       {
  33.          pPane.SendMessage("TansitionInFinished", SendMessageOptions.DontRequireReceiver);
  34.       }
  35.    }
  36.    
  37.    void TweenPositionPopOutFinished()
  38.    {
  39.       mTransitionPopOutCount--;
  40.       if(mTransitionPopOutCount > 0 || mPaneStack.Count == 0)
  41.          return;
  42.      
  43.      
  44.       List<GameObject> pLastSet = mPaneStack[mPaneStack.Count - 1];
  45.       foreach(GameObject pPane in pLastSet)
  46.       {
  47.          TweenPosition pTweenPosition = pPane.GetComponent<TweenPosition>();
  48.          if(pTweenPosition != null)
  49.          {
  50.             pTweenPosition.Play(true);
  51.             pTweenPosition.eventReceiver = gameObject;
  52.             pTweenPosition.callWhenFinished = "TweenPositionPushInFinished";
  53.             mTransitionPushInCount++;
  54.          }
  55.       }
  56.    }
  57.    
  58.    void TweenPositionPushInFinished()
  59.    {
  60.       mTransitionPushInCount--;
  61.       if(mTransitionPushInCount > 0)
  62.          return;
  63.      
  64.    }
  65.    
  66.    // gets the current level for future re-wind call
  67.    public int getLevelCount()
  68.    {
  69.       return mPaneStack.Count;
  70.    }
  71.    
  72.    public void pushPanes(List<GameObject> pListSet, string callWhenFinished, GameObject pEventReceiver)
  73.    {
  74.       if(mPaneStack.Count == 0)
  75.       {
  76.          mPaneStack.Add(pListSet);
  77.          return;
  78.       }
  79.      
  80.       mLastSet = mPaneStack[mPaneStack.Count - 1];
  81.       mNextPanelSet = pListSet;
  82.       foreach(GameObject pPane in mLastSet)
  83.       {
  84.          if(mNextPanelSet.Contains(pPane))
  85.             continue;
  86.          
  87.          TweenPosition pTweenPosition = pPane.GetComponent<TweenPosition>();
  88.          if(pTweenPosition != null)
  89.          {
  90.             pTweenPosition.Play(false);
  91.             pTweenPosition.eventReceiver = gameObject;
  92.             pTweenPosition.callWhenFinished = "TweenPositionPushOutFinished";
  93.             mTransitionPushOutCount++;
  94.          }
  95.       }
  96.    }
  97.    
  98.    public List<GameObject> popPanes()
  99.    {
  100.       if(mPaneStack.Count < 2)
  101.          return null;
  102.      
  103.       List<GameObject> p2ndToLastSet   = mPaneStack[mPaneStack.Count - 2];
  104.       List<GameObject> pLastSet        = mPaneStack[mPaneStack.Count - 1];
  105.       foreach(GameObject pPane in pLastSet)
  106.       {
  107.          if(p2ndToLastSet.Contains(pPane))
  108.             continue;
  109.          
  110.          TweenPosition pTweenPosition = pPane.GetComponent<TweenPosition>();
  111.          if(pTweenPosition != null)
  112.          {
  113.             pTweenPosition.Play(false);
  114.             pTweenPosition.eventReceiver     = gameObject;
  115.             pTweenPosition.callWhenFinished  = "TweenPositionPopOutFinished";
  116.             mTransitionPopOutCount++;
  117.          }
  118.       }
  119.       mPaneStack.Remove(pLastSet);
  120.       return pLastSet;
  121.    }
  122.