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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容