Author Topic: Animating sprite fill and color does not work  (Read 9100 times)

laurens.tjong

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Animating sprite fill and color does not work
« on: August 19, 2014, 07:34:35 AM »
Hello There

I am creating short tutorial animations explaining the basics of a game. For this I am using the same NGUI sprites as the sprites in the working ingame interface except these sprites have no functional logic attached to them.

I am using mecanim to animate al the tutorial events. The problem is when I want to color a sprite or change a fill setting of a sprite using the animation editor, this does not get animated. The panel is not checked as being static...

Does anybody know if this is a known issue?

« Last Edit: August 19, 2014, 07:40:08 AM by laurens.tjong »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating sprite fill and color does not work
« Reply #1 on: August 19, 2014, 01:40:38 PM »
"MFill" is a private variable. Animating it doesn't notify the widget that it changed. The fact that it shows up in the animator is an old Unity bug.

All NGUI interaction is done via properties instead UIWidget.fillAmount is what should be modified. If you want to do it via an animation, you need to write an intermediate script like so:
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditMode]
  4. [RequireComponent(typeof(UIWidget))]
  5. public class AnimatedFill : MonoBehaviour
  6. {
  7.     [Range(0f, 1f)]
  8.     public float fillAmount = 1f;
  9.  
  10.     UIWidget mWidget;
  11.  
  12.     void Awake () { mWidget = GetComponent<UIWidget>(); }
  13.     void Update () { mWidget.fillAmount = fillAmount; }
  14. }
Attach this script to your widget and animate this script's "fillAmount" value instead of "MFill".

laurens.tjong

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Animating sprite fill and color does not work
« Reply #2 on: August 19, 2014, 04:18:44 PM »
Great Aren,

Thank you very much for the reply, this will help us a great deal. Now we know for sure that we will have to use this small workaround.

Right now we use mecanim to move panels in and out of the screen i would think that with all the focus on mecanim from unity, NGUI would benefit from embracing the animation tool as a great addition to the NGUI workflow. Thanks again

Laurens

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating sprite fill and color does not work
« Reply #3 on: August 20, 2014, 02:26:44 PM »
The only way to "embrace" it is to expose variables making them public, and then check to see if they changed in every single Update(). This will hurt performance.

This extra component approach lets you animate things, and it won't affect performance of UI elements that are not animated.

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: Animating sprite fill and color does not work
« Reply #4 on: December 18, 2019, 12:47:34 AM »
hello, i'm facing the same problem and i tried this script but mWidget.fillAmount is not defined anymore, what i have to use to replace it?