Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: xikky on August 02, 2013, 08:42:23 AM

Title: Is it possible to tween all objects within a panel?
Post by: xikky on August 02, 2013, 08:42:23 AM
I tried alpha tween on a panel but the tween is only applied to sprites that are direct children of the panel. Other sprites contained as children of Gameobjects, within the panel are not affected. Can I fix this?
Title: Re: Is it possible to tween all objects within a panel?
Post by: Malzbier on August 02, 2013, 09:40:16 AM
Its very easy to build a tweener for panel alpha. (Took me 1 minute)

(Converted form the normal alpha tween script)
  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Tween the panels's alpha.
  5. /// </summary>
  6.  
  7. [AddComponentMenu("NGUI/Tween/PanelAlpha")]
  8. public class TweenPanelAlpha : UITweener
  9. {
  10.         public float from = 1f;
  11.         public float to = 1f;
  12.  
  13.         Transform mTrans;
  14.         UIPanel mPanel;
  15.  
  16.         /// <summary>
  17.         /// Current alpha.
  18.         /// </summary>
  19.  
  20.         public float alpha { get { return mPanel.alpha; } set { mPanel.alpha = value; } }
  21.  
  22.         /// <summary>
  23.         /// Find all needed components.
  24.         /// </summary>
  25.  
  26.         void Awake () { mPanel = GetComponentInChildren<UIPanel>(); }
  27.  
  28.         /// <summary>
  29.         /// Interpolate and update the alpha.
  30.         /// </summary>
  31.  
  32.         override protected void OnUpdate (float factor, bool isFinished) { alpha = Mathf.Lerp(from, to, factor); }
  33.  
  34.         /// <summary>
  35.         /// Start the tweening operation.
  36.         /// </summary>
  37.  
  38.         static public TweenAlpha Begin (GameObject go, float duration, float alpha)
  39.         {
  40.                 TweenAlpha comp = UITweener.Begin<TweenAlpha>(go, duration);
  41.                 comp.from = comp.alpha;
  42.                 comp.to = alpha;
  43.                 return comp;
  44.         }
  45. }
Title: Re: Is it possible to tween all objects within a panel?
Post by: xikky on August 02, 2013, 11:51:39 AM
Thanks! works perfect.
Title: Re: Is it possible to tween all objects within a panel?
Post by: ArenMook on August 02, 2013, 08:12:50 PM
Built-in TweenAlpha works with panels.