源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

52 行
1.4 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5. [AddComponentMenu("UI/Effects/Gradient")]
  6. public class Gradient : BaseMeshEffect
  7. {
  8. public Color32 topColor = new Color32(248, 217, 44, 255);
  9. public Color32 bottomColor = new Color32(255, 255, 255, 255);
  10. public override void ModifyMesh(VertexHelper vh)
  11. {
  12. if (!IsActive())
  13. {
  14. return;
  15. }
  16. int count = vh.currentVertCount;
  17. if (count == 0) return;
  18. List<UIVertex> vertexs = new List<UIVertex>();
  19. for (int i = 0; i < count; i++)
  20. {
  21. UIVertex vertex = new UIVertex();
  22. vh.PopulateUIVertex(ref vertex, i);
  23. vertexs.Add(vertex);
  24. }
  25. float topY = vertexs[0].position.y;
  26. float bottomY = vertexs[0].position.y;
  27. for (int i = 1; i < count; i++)
  28. {
  29. float y = vertexs[i].position.y;
  30. if (y > topY)
  31. {
  32. topY = y;
  33. }
  34. else if (y < bottomY)
  35. {
  36. bottomY = y;
  37. }
  38. }
  39. float height = topY - bottomY;
  40. for (int i = 0; i < count; i++)
  41. {
  42. UIVertex vertex = vertexs[i];
  43. Color32 color = Color32.Lerp(bottomColor, topColor, (vertex.position.y - bottomY) / height);
  44. vertex.color = color;
  45. vh.SetUIVertex(vertex, i);
  46. }
  47. }
  48. }