Author Topic: UIButtonPlayAnimation moving pivot of second animation depending on first.  (Read 3552 times)

theprojectabot

  • Guest
I have set up a main menu panel. In a child button within this panel I have two UIButtonPlayAnimation scripts attached.   The first moves this main menu panel up and out of the screen view by triggering an animation when the button is clicked.   The second UIButtonPlayAnimation script triggers a new panel to slide from the bottom of the screen into view.   

However, when the button is clicked the first panel slides up and out of the screen and the second panel seems to be using the first panels pivot as its starting position for animating and thusly slides up and out of the top of the screen instead of sliding from the buttom up into the screen.


If I run the animations with out utilizing UIButtonPlayAnimation... for example just setting the animation to play automatically in the animation componenet, and I toggle the activeness of the panel, everything works fine.... This of course is not a solution as I need the activation of the panel and its subsequent slide into view to be triggered by a button press.

Thoughts?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #1 on: February 06, 2013, 10:22:21 PM »
I suggest looking closer at what you're doing. All the UIButtonPlayAnimation does is literally triggers the animation to be played.

theprojectabot

  • Guest
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #2 on: February 07, 2013, 12:22:34 AM »
Indeed after looking more closely I see what is causing the problem however I do not know why this is occuring.   

The reason for the weird behavior is that the Animation component attached to the second panel is enabled but when the whole group is activated from the UIButtonPlayAnimation script(and an ActiveAnimation component is instantiated onto the panel) the active flag of the Animation Component is mysteriously turned off.  Which subsequently makes the child UIAnchors behave oddly.

Im digging into why this Animation component disables it self but I havent found a reason yet.   

I have checked the animation curve and made sure that I am not toggling the 'animation enabled' within the animation itself...

theprojectabot

  • Guest
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #3 on: February 07, 2013, 12:35:05 AM »
ln 154: ActiveAnimation.cs, turns the mAnim.enabled = false;

why?  This was what was killing my anims.

theprojectabot

  • Guest
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #4 on: February 07, 2013, 12:45:43 AM »
So with that line removed and placing checking code within the beginning of the UIAnchor Update() concerning parental animations currently playing, I have my animations and anchored UI looking good.

my special bit of code in UIAnchor, containingAnim is a public reference to the parental Animation that animates the whole panel:
  1. void Update ()
  2.         {
  3.                 if (mAnim != null && mAnim.enabled && mAnim.isPlaying) return;
  4.                
  5.                 if(containingAnim != null && containingAnim.enabled && containingAnim.isPlaying)
  6.                         return;
  7.                
  8.                 if(frameSnapped) return;
  9.                
  10.                 if(snapOnlyOneFrame)
  11.                 {      
  12.                         frameSnapped = true;
  13.                 }
  14. ///I frame snap so that when the container to all the UIAnchors(this is my panel actually) is enabled from a play animation it will do one frame run through of the snapping code and then not do the anchors anymore... allowing for anims and such.   Make sure to not have static'd or selected the fill options on your panel or else you may have some mid frame lockups for your assets.  Aka the colliders will move but the drawn images might be stuck.(at least thats what I found)
  15. .....rest of code

theprojectabot

  • Guest
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #5 on: February 07, 2013, 12:47:14 AM »
I did all this because I want device agnostic control snapping plus animation abilities.  Perhaps its a hack or not what Aren envision'd Im all ears for a better method yos. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #6 on: February 07, 2013, 09:59:20 AM »
Never animate panels that have UIAnchors inside. Anchors move the object, so does your animation. The two fight over object repositioning. I'm surprised it worked at all for you. You need to structure your UI like this:

Anchor
- Panel (animation)

theprojectabot

  • Guest
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #7 on: February 07, 2013, 12:53:39 PM »
Aren it works fine because I only allow UIAnchors to work for one frame.   As for the Anchor->UIPanel construction.  Wouldn't I then have a bunch of panels all associated with various anchors?  I would then need a parental object above all those anchors and animate that, as I am wanting to move all the widgets in their associated anchored corners.  However from my tests in that organization it wont allow animation of all those separate panels from a master offset.  That is why I went this route.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonPlayAnimation moving pivot of second animation depending on first.
« Reply #8 on: February 07, 2013, 11:10:46 PM »
Nothing is stopping you from having more than one panel underneath one anchor.

And unless you explicitly remove the said anchors, they force set the position every single update.