美文网首页
Unity ITweenColor修改增加Graphic支持

Unity ITweenColor修改增加Graphic支持

作者: thrt520 | 来源:发表于2017-07-12 10:08 被阅读0次

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

    相关文章

      网友评论

          本文标题:Unity ITweenColor修改增加Graphic支持

          本文链接:https://www.haomeiwen.com/subject/wwnvhxtx.html