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;
}