Author Topic: Is it possible to tween all objects within a panel?  (Read 8041 times)

xikky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Is it possible to tween all objects within a panel?
« 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?

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Is it possible to tween all objects within a panel?
« Reply #1 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. }

xikky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: Is it possible to tween all objects within a panel?
« Reply #2 on: August 02, 2013, 11:51:39 AM »
Thanks! works perfect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Is it possible to tween all objects within a panel?
« Reply #3 on: August 02, 2013, 08:12:50 PM »
Built-in TweenAlpha works with panels.