美文网首页
Unity 扩展系统组件(笔记)

Unity 扩展系统组件(笔记)

作者: 木子才 | 来源:发表于2017-05-10 16:32 被阅读0次

    无需引入,如同原生一样调用。

    public static class MZCTools {
        public static void mzcSetColor(this GameObject gameObject, Color color) {
            if (gameObject) {
                Renderer renderer = gameObject.GetComponent<Renderer> ();
                if (renderer) {
                    renderer.material.color = color;
                } else {
                    Light light = gameObject.GetComponent<Light> ();
                    if (light) {
                        light.color = color;
                    }
                }
            }
        }
    }
    

    这个工具类叫 MZCTools,里面的方法统一都代有前缀 mzc,为了避免和系统或其他第三方冲突,假如你了解过 iOS 开发,你就懂我的话了。
    这个笔记只有一个方法在:mzcSetColor。
    正如他的名字,这货是用来设置颜色的。
    现在就只做了两种情况的判断,或许还有其他情况,这里就抛砖引玉,留给无穷的想象给各位了。

    调用方式,和原生的一样。

    GameObject go = GameObject.Find("theL");
    go.mzcSetColor (Color.green);
    

    无需引用,方便快捷,可以愉快的写代码啊~~

    相关文章

      网友评论

          本文标题:Unity 扩展系统组件(笔记)

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