【Unity&NGUI】Label的颜色动态改变以及渐变颜色
来源:互联网 发布:矩阵计算 第3版 pdf 编辑:程序博客网 时间:2024/05/01 18:31
本篇文章讲述使用代码改变
NGUI的Label的Tween的Style
NGUI的Label的Tween Color的改变的颜色
使用代码控制NGUI的Label改变颜色有两种方法
1.直接在NGUI的Label的Text里面输入颜色RGB代码
点击Color Tint的Hex Color 就是对应RGBA,A是Alpha值
2.通过代码改变
如下所示,通过代码改变text也是可以实现的
R = 255 /255;
G = 255 / 255;
B = 255 / 255;
A = 255 / 255;
//this.GetComponent<UILabel>().text = "[99ff66]Strength";
this.GetComponent<UILabel>().color =new Color(R, G, B, A);
NGUI的UI的Label怎么实现颜色的渐变
NGUI---Tween---Color,如果是固定的就直接添加组件,进行设置就行了
如果想使用代码动态设置,可以把Tween Color右键Edit Script打开,就可以设置相对应的属性
一步一步查表可以得到NGUI的Label的Tween的Style的设置如下所示
gameObject.GetComponent<TweenColor>().style = UITweener.Style.PingPong;
gameObject.GetComponent<TweenColor>().style = UITweener.Style.Once;
gameObject.GetComponent<TweenColor>().style = UITweener.Style.Loop;
PingPong从From值到To,从To 到From不停变化
Once从From值到To,变化一次
PingPong从From值到To,不停变化
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LabelChangeColor : MonoBehaviour {
private float R;
private float G;
private float B;
private float A;
// Use this for initialization
void Start () {
R = 1 /255;
G = 1 / 255;
B = 1 / 255;
A = 1 / 255;
//this.GetComponent<UILabel>().text = "[99ff66]Strength";
//this.GetComponent<UILabel>().color =new Color(R, G, B, A);
if (!gameObject.GetComponent<TweenColor>())
{
gameObject.AddComponent<TweenColor> ().from = new Color(R, G, B, A);
gameObject.GetComponent<TweenColor>().to = new Color(1, 1, 1, 1);
gameObject.GetComponent<TweenColor>().style = UITweener.Style.PingPong;
}
}
public void LabelChangeColorRGBA(float r,float g,float b,float a)
{
R = r;
G = g;
B = b;
A = a;
this.GetComponent<UILabel>().color = new Color(R, G, B, A);
}
}
duration意思是延迟,使用方法gameObject.GetComponent<TweenColor>().delay = 2f;//延迟2S
参考文章:
1.NGUI设置UIButton的颜色值影响子UISprite.color值
2.[3D理论]Unity3D NGUI的label怎么键入不同颜色的字体
3.NGUI中的颜色字体如何调?
4.unity开发 --------- NGUI (UIButtonColor、TweenColor、Light)
- 【Unity&NGUI】Label的颜色动态改变以及渐变颜色
- ios label颜色渐变
- label字体颜色的彩色渐变
- label 省略号颜色改变
- unity 改变物体的颜色
- 改变控件的边框颜色(示例Label)
- 改变label部分文字的颜色
- 改变label中个别字的颜色
- 【Unity&NGUI】查找对象并改变颜色的几种方式
- NGUI 动态改变Label字体
- 背景颜色渐变动态
- Android 颜色动态渐变
- 动态改变字体的颜色
- 实现Label的鼠标点击响应,以及获取焦点后改变颜色
- label标题文字改变颜色
- Qt制作的动态颜色渐变表盘
- Android动态渐变view的颜色
- Android:动态设置颜色渐变的进度条
- 菜鸡的从零开始的web笔记-锚点
- 内存溢出的几点原因
- MySQL5.6多实例部署
- 通过实例浅谈Spring运作机制
- 【网站高性能 2】----RAID vs HDFS
- 【Unity&NGUI】Label的颜色动态改变以及渐变颜色
- 斐波那契查找
- zoj1229
- 【Javascript基础篇】—--原型对象(prototype)的三个常用方法
- Android 实现个性的ViewPager切换动画 实战PageTransformer(兼容Android3.0以下)
- shell脚本实现上传日志到ftp服务器
- 透视学理论(九)
- 安卓json数据解析
- Mysql绿色版安装,Mysql创建用户及数据库