Unity ITweenColor修改增加Graphic支持

itween原生不支持UGUI的组件颜色动画,而项目中经常会遇到这种需求,比如飘字淡入淡出~~巴拉巴拉 , 为了解决这个问题主要请参考这位大神的文章 http://www.cnblogs.com/YYRise/p/4432198.html,我在他的基础上做了修改,主要是把image和rawImage整合成Graphic,因为UGUI所有显示组件都是继承的Grapic类,这样所有的UGUI组件都可以动态修改颜色了。一点微小的工作~~~详细的可以看那位大神的博客

ex修改位置:
//set tempColor and base fromColor:
if(target.GetComponent<GUITexture>()){
tempColor=fromColor=target.GetComponent<GUITexture>().color;
}else if(target.GetComponent<GUIText>()){
tempColor=fromColor=target.GetComponent<GUIText>().material.color;
}else if(target.GetComponent<Renderer>()){
tempColor=fromColor=target.GetComponent<Renderer>().material.color;
}else if(target.GetComponent<Light>()){
tempColor=fromColor=target.GetComponent<Light>().color;
}else if(target.GetComponent<UnityEngine.UI.Graphic>()){
tempColor=fromColor= target.GetComponent<UnityEngine.UI.Graphic>().color;
}
if(target.GetComponent<GUITexture>()){
target.GetComponent<GUITexture>().color=fromColor;
}else if(target.GetComponent<GUIText>()){
target.GetComponent<GUIText>().material.color=fromColor;
}else if(target.GetComponent<Renderer>()){
target.GetComponent<Renderer>().material.color=fromColor;
}else if(target.GetComponent<Light>()){
target.GetComponent<Light>().color=fromColor;
}else if(target.GetComponent<UnityEngine.UI.Graphic>()){
target.GetComponent<UnityEngine.UI.Graphic>().color=fromColor;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容