ugui中text的打字机渐显功能
来源:互联网 发布:mysql qps 编辑:程序博客网 时间:2024/06/07 10:44
项目中有涉及到,就贴出来交流
using UnityEngine;using System.Collections;using UnityEngine.UI;using System.Collections.Generic;public class Typewriter_alpha : MonoBehaviour { public float TimeSpan = 0.1f; public int ColorSpan = 50;//1-50 public bool ColorAlphaSpan = true; private bool changeFlag = true; private string originStr; private string nowStr; private int index; private float timePiece; private string originColor; private Dictionary<int,int> alphaLine = new Dictionary<int, int>(); private string ColorToHex(Color color){ int Val = 0; Val |= Mathf.RoundToInt (color.r * 255f) << 24; Val |= Mathf.RoundToInt (color.g * 255f) << 16; Val |= Mathf.RoundToInt (color.b * 255f) << 8; Val |= Mathf.RoundToInt (color.a * 255f); return Val.ToString ("x8").Substring(0,6); //返回值去掉alpha值 } //<color=#0000ff00></color> rgba a:0%00 25%40 50%80 100%ff //使单字透明度渐变 需要加注 // Use this for initialization void OnEnable () { originStr = this.GetComponent<Text> ().text; originColor = ColorToHex (this.GetComponent<Text> ().color); this.GetComponent<Text> ().text = ""; nowStr = ""; index = 1; changeFlag = true; timePiece = Time.time; alphaLine.Clear (); if (ColorAlphaSpan) alphaLine.Add (0, 0); } // Update is called once per frame void Update () { if (Time.time - timePiece > TimeSpan&&changeFlag) { if (ColorAlphaSpan) { if (alphaLine.Count != 0) { for (int i = 0; i < index; ++i) { if (i == index - 1 && !alphaLine.ContainsKey (i)) { alphaLine.Add (i, 0); } if (alphaLine.ContainsKey (i)) { if (alphaLine [i] >= 100) { alphaLine.Remove (i); nowStr += originStr.Substring (i, 1); if (alphaLine.Count == 0) nowStr = originStr; } else { nowStr += "<color=#" + originColor; //int值小于10的时候补个0 不然就显示为白色而不是透明度很低的颜色了 if (alphaLine [i] < 10) nowStr += "0"+alphaLine[i]+">"; else nowStr += alphaLine [i].ToString () + ">"; nowStr += originStr.Substring (i, 1); nowStr += "</color>"; alphaLine [i] += ColorSpan; } } else { nowStr += originStr.Substring (i, 1); } } this.GetComponent<Text> ().text = nowStr; nowStr = ""; if (index < originStr.Length) index++; } else { changeFlag = false; } } else { this.GetComponent<Text> ().text = originStr.Substring (0, index++); if (index > originStr.Length) changeFlag = false; } timePiece = Time.time; } }}
0 0
- ugui中text的打字机渐显功能
- UGUI 打字机效果
- UGUI打字机效果
- UGUI实现打字机效果
- UGUI打字机效果
- C#中窗口渐显的方法
- VC#中渐显窗口的方法
- VC#中渐显窗口的方法
- Unity UGUI——提供可视功能的UI组件(Text)
- UGUI - Text
- Unity3D-UGUI的Text组件渐变效果
- 【Unity】UGUI的Text各种小问题
- unity-ugui的text字体模糊解决办法
- 图片的渐显播放
- 文本框的渐显
- unity3d的ugui中,text内容显示不完全甚至放大消失的问题(text 中字符不能完全显示,字符丢失)
- UGUI Text Gradient
- Unity UGUI--Text组件
- reactNative bug
- 24c32,i2c原理
- SQL语法——保留字的使用
- 开发微信公众号需要配置的几个地方
- CodeForces-450E Jzzhu and Apples 【数学+贪心构造】
- ugui中text的打字机渐显功能
- Gradle配置全局变量
- iOS 一些笔记
- 微信小程序---自动定位,天气预报
- Foxit Reader以及Foxit Phantom如何设置页面固定大小
- 流式布局
- SpringBoot快速入门,不继承SpringBoot父依赖项目
- Java利用System.getProperty("file.encoding")获取编码分析
- SQL语法——视图创建