Author Topic: Proposed change to TweenAlpha  (Read 2835 times)

TypoStraw

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 19
    • View Profile
Proposed change to TweenAlpha
« 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. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Proposed change to TweenAlpha
« Reply #1 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.