查看: 1677|回复: 0
打印 上一主题 下一主题

[其他] UGUI字体特效DIY

[复制链接]
may    

8830

主题

80

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52304
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-9-26 00:11:13 |只看该作者 |倒序浏览

UGUI自带两个字体效果--Outline 和 Shadow

而渐变效果实现木有,以下是一个简单实现:
  • //---------------------UGUI Text Gradient---------------------
  • 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;
  •                 }
  •         }
  • }




UGUI文字/UI特效的代码示例
  • using System.Collections.Generic;
  • using UnityEngine;
  • using UnityEngine.UI;
  • /**
  • * Modify the given vertices so they follow a sin curve
  • */
  • public class BaseVertexEffect_Test : BaseVertexEffect
  • {
  •         public float scale = 10f;
  •         public float amplitude = 35f;
  •         public float phase = 0f;
  •         public override void ModifyVertices(List<UIVertex> verts)
  •         {
  •                 if (!IsActive ())
  •                         return;
  •         int prevLength = verts.Count;
  •         for (int index = 0; index < prevLength; index++)
  •                 {
  •                         var uiVertex = verts[index];
  •             uiVertex.color = new Color(0,0,0,0.5f);
  •                         uiVertex.position.z = Mathf.Sin (uiVertex.position.x * scale + phase) * amplitude;
  •             verts.Add(uiVertex);//增加需要渲染的顶点
  •                         //verts[index] = uiVertex;//或者覆盖原来顶点
  •                 }
  •         }
  • }


分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-6 16:51 , Processed in 0.078074 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部