zoukankan      html  css  js  c++  java
  • Unity 2017 文字颜色渐变

     1 using System.Collections;
     2 using System.Collections.Generic;
     3 using UnityEngine;
     4 using UnityEngine.UI;
     5 
     6 [AddComponentMenu("UI/Effects/GradientText")]
     7 public class GradientText : BaseMeshEffect
     8 {
     9     [SerializeField]
    10     private Color32 topColor = Color.white;
    11 
    12     [SerializeField]
    13     private Color32 bottomColor = Color.black;
    14 
    15     public override void ModifyMesh(VertexHelper vh)
    16     {
    17         if (!IsActive() || vh.currentVertCount == 0)
    18             return;
    19         List<UIVertex> vertices =  new List<UIVertex>();
    20         vh.GetUIVertexStream(vertices);
    21         float bottomY = vertices[0].position.y;
    22         float topY = vertices[0].position.y;
    23         for (int i = 1; i < vertices.Count; i++ )
    24         {
    25            if( vertices[i].position.y > topY) {
    26                 topY = vertices[i].position.y;
    27             }
    28             else if (vertices[i].position.y < bottomY)
    29             {
    30                 bottomY = vertices[i].position.y;
    31             }
    32         }
    33         float uiElementHeight = topY- bottomY;
    34         UIVertex v = new UIVertex();
    35         for (int i = 0; i<vh.currentVertCount; i++)
    36         {
    37         vh.PopulateUIVertex(ref v, i);
    38         v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight);
    39         vh.SetUIVertex(v, i);
    40         }
    41     }
    42 }

  • 相关阅读:
    100以内质数的算法
    WebAPI和WebService的区别
    .net core 2.0 数据访问-迁移
    .net core 2.0 Redis的基本使用
    .net core 2.0 Autofac
    net core 2.0 + Autofac的坑
    MVC路由机制
    MVC原理
    CentOS安装GIt、上传项目到git仓库
    ARM 汇编指令集 特点5:ARM 多级指令流水线
  • 原文地址:https://www.cnblogs.com/pmsl/p/7615891.html
Copyright © 2011-2022 走看看