Author Topic: Animating panel alpha through Unity  (Read 5718 times)

fatlemongames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Animating panel alpha through Unity
« on: February 04, 2014, 03:24:51 AM »
Hello,

After updating to NGUI 3.4.8 from 3.3.3 (using the new version number convention) I'm having an issue with panels that animate their alpha value.

I'm using Unity's animation system to fade panels in and out by animating their (visible in inspector) alpha value. This has worked well before, but after the update it seems like if a panel starts its animation from 0 alpha, it will never be visible. Panels that are nested inside this panel may be visible, but the parent panel is not.

I have corrected this by forcibly calling UIPanel.SetDirty() on the panel if it's animating, but I wonder if this is a bug or if I'm doing something wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating panel alpha through Unity
« Reply #1 on: February 04, 2014, 03:50:26 AM »
UIPanel.alpha is a property, and Unity is not able to animate properties. What you are animating instead is "MAlpha", I'm guessing -- which is a private variable. The fact that Unity lets you do that is a bug in Unity that has existed for ages.

You need to use an intermediate script -- AnimatedAlpha.

Attach it to your panel (or a widget) and animate its alpha instead of the panel when using the Unity's animation system.

fatlemongames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Animating panel alpha through Unity
« Reply #2 on: February 04, 2014, 04:17:38 AM »
Great, thanks for the clarification! I will change my animations accordingly.

Acheron Studio

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Animating panel alpha through Unity
« Reply #3 on: February 13, 2014, 09:04:46 PM »
Previous versions of NGUI allowed animating the mAlpha property, so the reason it shows up in the editor is probably because it was set up before updating.

I personally preferred it when you could animate it using the property in UIPanel.

I'd like to suggest these two improvements to make AnimatedAlpha a little nicer to use:

Add a [Range(0, 1)] tag to alpha so that you get a nice draggable interface in the editor
Add [ExecuteInEditMode] to the class so you can see fading changes while playing and debugging animations in the editor

Apart from some strange changes, recent updates have been great :) I personally really like the addition of nested panels being affected by the alpha of its parent. Much needed addition!

paynechu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Animating panel alpha through Unity
« Reply #4 on: February 13, 2014, 10:18:56 PM »
agree with Acheron Studio
AnimatedAlpha seems to plain can a bit improve
And don't know why the old version is work even just animate MAlpha directly. Maybe SetDirty that time is called incorrectly so it work? And now fixed the SetDirty so it not work?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating panel alpha through Unity
« Reply #5 on: February 14, 2014, 05:15:41 AM »
Good suggestions, Acheron. I'll add them to 3.5.0.