名动江湖
- 麒麟币
- 2555 枚
- 任务币
- 0 枚
- 威望
- 0 点
- 贡献
- 30 点
- 主题
- 172贴
- 在线时间
- 15 小时
|
UGUI Text渐变效果实现(Gradient)
UGUI自带两个字体效果--Outline 和 Shadow
而渐变效果实现木有,以下是社区中的实现,供参考使用:另外一个简单实现:- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- [AddComponentMenu("UI/Effects/Gradient")]
- public class Gradient : BaseVertexEffect {
- [SerializeField]
- private Color32 topColor = Color.white;
- [SerializeField]
- private Color32 bottomColor = Color.black;
- public override void ModifyVertices(List<UIVertex> vertexList) {
- if (!IsActive()) {
- return;
- }
- int count = vertexList.Count;
- float bottomY = vertexList[0].position.y;
- float topY = vertexList[0].position.y;
- for (int i = 1; i < count; i++) {
- float y = vertexList.position.y;
- if (y > topY) {
- topY = y;
- }
- else if (y < bottomY) {
- bottomY = y;
- }
- }
- float uiElementHeight = topY - bottomY;
- for (int i = 0; i < count; i++) {
- UIVertex uiVertex = vertexList;
- uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight);
- vertexList = uiVertex;
- }
- }
- }
[color=rgb(51, 102, 153) !important]复制代码% |
|