Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: TypoStraw on August 27, 2014, 05:02:08 PM

Title: Proposed change to TweenAlpha
Post by: TypoStraw on August 27, 2014, 05:02:08 PM
In 3.7.0 TweenAlpha was changed so it also works with renderers.

However, the SpriteRenderer component has a color variable which can be used instead of changing the color in the material.

The changes:
- Added a SpriteRender variable after mMat called sRend.
- Added the following in the Cache() method:
  1. if (mRect == null)
  2. {
  3.     sRend = GetComponent<SpriteRenderer>();
  4.  
  5.     if(sRend == null)
  6.     {
  7.                 // get material
- Updated the value property to include checks for sRend:
  1. get
  2. {
  3.         if (!mCached) Cache();
  4.         if (mRect != null) return mRect.alpha;
  5.         if (sRend != null) return sRend.color.a; // <------
  6.         return mMat.color.a;
  7. }
  8. set
  9. {
  10.         if (!mCached) Cache();
  11.  
  12.         if (mRect != null)
  13.         {
  14.                 mRect.alpha = value;
  15.         }
  16.     else if(sRend != null)  // <------
  17.     {
  18.         Color c = sRend.color;
  19.         c.a = value;
  20.         sRend.color = c;
  21.     }
  22.         else
  23.         {
  24.                 Color c = mMat.color;
  25.                 c.a = value;
  26.                 mMat.color = c;
  27.         }
  28. }
Title: Re: Proposed change to TweenAlpha
Post by: ArenMook on August 28, 2014, 08:48:04 PM
Seems fine to me, but I'll call it something else. I'll do similar tweaks to the TweenColor as well.