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

    using UnityEngine;
    using System.Collections.Generic;
    using UnityEngine.UI;
     
    [AddComponentMenu("UI/Effects/Text Vertical Gradient Color")]
    [RequireComponent(typeof(Text))]
    public class TextVerticalGradientThreeColor : BaseMeshEffect
    {
        public Color colorTop = Color.red;
        public Color colorCenter = Color.blue;
        public Color colorBottom = Color.green;
     
        public bool MultiplyTextColor = false;
     
        protected TextVerticalGradientThreeColor()
        {
        }
     
        public static Color32 Multiply(Color32 a, Color32 b)
        {
            a.r = (byte) ((a.r * b.r) >> 8);
            a.g = (byte) ((a.g * b.g) >> 8);
            a.b = (byte) ((a.b * b.b) >> 8);
            a.a = (byte) ((a.a * b.a) >> 8);
            return a;
        }
     
        private void ModifyVertices(VertexHelper vh)
        {
            List<UIVertex> verts = new List<UIVertex>(vh.currentVertCount);
            vh.GetUIVertexStream(verts);
            vh.Clear();
     
            int step = 6;
     
            for (int i = 0; i < verts.Count; i += step)
            {
                //6 point
                var tl = multiplyColor(verts[i + 0], colorTop);
                var tr = multiplyColor(verts[i + 1], colorTop);
                var bl = multiplyColor(verts[i + 4], colorBottom);
                var br = multiplyColor(verts[i + 3], colorBottom);
                var cl = calcCenterVertex(verts[i + 0], verts[i + 4]);
                var cr = calcCenterVertex(verts[i + 1], verts[i + 2]);
     
                vh.AddVert(tl);
                vh.AddVert(tr);
                vh.AddVert(cr);
                vh.AddVert(cr);
                vh.AddVert(cl);
                vh.AddVert(tl);
     
                vh.AddVert(cl);
                vh.AddVert(cr);
                vh.AddVert(br);
                vh.AddVert(br);
                vh.AddVert(bl);
                vh.AddVert(cl);
            }
     
            for (int i = 0; i < vh.currentVertCount; i += 12)
            {
                vh.AddTriangle(i + 0, i + 1, i + 2);
                vh.AddTriangle(i + 3, i + 4, i + 5);
                vh.AddTriangle(i + 6, i + 7, i + 8);
                vh.AddTriangle(i + 9, i + 10, i + 11);
            }
        }
     
        private UIVertex multiplyColor(UIVertex vertex, Color color)
        {
            if (MultiplyTextColor)
                vertex.color = Multiply(vertex.color, color);
            else
                vertex.color = color;
            return vertex;
        }
     
        private UIVertex calcCenterVertex(UIVertex top, UIVertex bottom)
        {
            UIVertex center=new UIVertex();
            center.normal = (top.normal + bottom.normal) / 2;
            center.position = (top.position + bottom.position) / 2;
            center.tangent = (top.tangent + bottom.tangent) / 2;
            center.uv0 = (top.uv0 + bottom.uv0) / 2;
            center.uv1 = (top.uv1 + bottom.uv1) / 2;
     
            if (MultiplyTextColor)
            {
                //multiply color
                var color = Color.Lerp(top.color, bottom.color, 0.5f);
                center.color = Multiply(color, colorCenter);
            }
            else
            {
                center.color = colorCenter;
            }
     
            return center;
        }
     
        #region implemented abstract members of BaseMeshEffect
     
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!this.IsActive())
            {
                return;
            }
     
     
            ModifyVertices(vh);
        }
     
        #endregion
    }
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using System.Collections.Generic;
      
    [RequireComponent(typeof(Text))]
    public class TextVerticalGradientTwoColor : BaseMeshEffect
    {
      
         
        public Color colorTop = Color.red;
        public Color colorBottom = Color.green;
      
        protected TextVerticalGradientTwoColor()
        {
      
        }
      
        private static void setColor(List<UIVertex> verts, int index, Color32 c)
        {
            UIVertex vertex = verts[index];
            vertex.color = c;
            verts[index] = vertex;
        }
      
        private void ModifyVertices(List<UIVertex> verts)
        {
            for (int i = 0; i < verts.Count; i += 6)
            {
                setColor(verts, i + 0, colorTop);
                setColor(verts, i + 1, colorTop);
                setColor(verts, i + 2, colorBottom);
                setColor(verts, i + 3, colorBottom);
      
                setColor(verts, i + 4, colorBottom);
                setColor(verts, i + 5, colorTop);
            }
        }
      
        #region implemented abstract members of BaseMeshEffect
      
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!this.IsActive())
            {
                return;
            }
            List<UIVertex> verts = new List<UIVertex>(vh.currentVertCount);
            vh.GetUIVertexStream(verts);
      
            ModifyVertices(verts);
      
            vh.Clear();
            vh.AddUIVertexTriangleStream(verts);
        }
      
        #endregion
    }
  • 相关阅读:
    [更新]一份包含: 采用RSA JWT(Json Web Token, RSA加密)的OAUTH2.0,HTTP BASIC,本地数据库验证,Windows域验证,单点登录的Spring Security配置文件
    fstab文件详解
    Struts2与Spring的Maven依赖冲突
    maven正确的集成命令-U -B 等
    CentOS6安装Jenkins
    CentOS6下Jenkins连接Git服务器出错的问题
    GitLab备份的创建与恢复
    开发App到上架应用市场需要经历什么?
    阅读笔记:A Few useful things to Know About machine Learning
    Feature Tools 简介
  • 原文地址:https://www.cnblogs.com/grassgarden/p/13725036.html
Copyright © 2011-2022 走看看