Guest User

Untitled

a guest
Dec 11th, 2019
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. [AddComponentMenu("UI/Effects/Gradient")]
  7. public class UIGradient : BaseMeshEffect
  8. {
  9.     public Color m_color1 = Color.white;
  10.     public Color m_color2 = Color.white;
  11.     [Range(-180f, 180f)]
  12.     public float m_angle = 0f;
  13.     public bool m_ignoreRatio = true;
  14.  
  15.     public override void ModifyMesh(VertexHelper vh)
  16.     {
  17.         if(enabled)
  18.         {
  19.             Rect rect = graphic.rectTransform.rect;
  20.             Vector2 dir = UIGradientUtils.RotationDir(m_angle);
  21.  
  22.             if (!m_ignoreRatio)
  23.                 dir = UIGradientUtils.CompensateAspectRatio(rect, dir);
  24.  
  25.             UIGradientUtils.Matrix2x3 localPositionMatrix = UIGradientUtils.LocalPositionMatrix(rect, dir);
  26.  
  27.             UIVertex vertex = default(UIVertex);
  28.             for (int i = 0; i < vh.currentVertCount; i++) {
  29.                 vh.PopulateUIVertex (ref vertex, i);
  30.                 Vector2 localPosition = localPositionMatrix * vertex.position;
  31.                 vertex.color *= Color.Lerp(m_color2, m_color1, localPosition.y);
  32.                 vh.SetUIVertex (vertex, i);
  33.             }
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment