背景由于要做Native2D的A* 算法寻路,所以必须进行Scene的网格划分,而进行了网格划分需要进行可视化的调试,需求就是这个逻辑。具体是实现如下效果,这里绿色的区域就是角色不能进入的区域(或者是走不进去的地方,大家玩网游都遇到过吧) 按照这个思路基本是两个问题,1、如何实现可视化调试;2、Unity如何绘制网格 实现1、Unity如何实现可视化调试 本文的实现完全围绕需求来走,就是需要在2D环境中实现可配置网格显示。先按照背景中的思路学习轮子,百度下基本下篇大牛的总结比较好,比较全 【风宇冲】图形化调试 http://blog.sina.com.cn/s/blog_471132920101gxzf.html 这里可耻的转载一下
这里根据我自己的要求,只要能在Editor模式下的Scene和Game中显示就可以了。 2、Unity如何绘制网格 在1中 大牛已经给出了方向和简单的列子,下面就是自己实现了,刚开始比较懒,还是想一步到位,直接找到一个类似DrawRect的函数直接在中绘制矩形,结果果然失败,找了很久也没有这样的函数和或者别人分享的。下面分享下自己搜集的方案 A、使用Mesh网格进行绘制 说实话我觉得这种方法对于我的需求是没什么实际作用的,而且看起来有些虚,最主要的问题是网格不可控制。
[C#]
纯文本查看
复制代码
B、第二个方法就是使用GL 这种方法其实还是比较底层的,竟然还用到了传说中的Shader,用于拔高也是不错的列子,而且看起来也不虚,但最主要的问题是网格不可控制。再说我也觉得用GL有点杀鸡用牛刀的感觉。
[C#]
纯文本查看
复制代码
C、第三个方法Gizmos.Draw 这也是我最终使用的方法,实现效果如下所示,其实Gizmos的功能很强大,可以绘制Mesh和Cude,在3D调试中用处不能小视。 这里主要遇到的问题是Gizmos没有提供DrawRect函数需要自己实现,这里其实本身没有什么技术难度,因为已经提供了DrawLine函数。自己比较懒,本来想看是否有现成的直接剽窃下,后来Seach未果,只能自己实现了,下面是实现函数,同时提供DrawPath和DrawLine函数这里是从itween里提取出来的
[C#]
纯文本查看
复制代码
总结程序员都懒总想找现成的,这次我提供个现成的给你哦。如果真对你有用别忘记给我投一票。 2016年度游戏蛮牛最受欢迎专栏作家评选,为他们投票! 别忘记我是恶魔猎手哦(wind2006) |
背景由于要做Native2D的A* 算法寻路,所以必须进行Scene的网格划分,而进行了网格划分需要进行可视化的调试,需求就是这个逻辑。具体是实现如下效果,这里绿色的区域就是角色不能进入的区域(或者是走不进去的地方,大家玩网游都遇到过吧) 按照这个思路基本是两个问题,1、如何实现可视化调试;2、Unity如何绘制网格 实现1、Unity如何实现可视化调试 本文的实现完全围绕需求来走,就是需要在2D环境中实现可配置网格显示。先按照背景中的思路学习轮子,百度下基本下篇大牛的总结比较好,比较全 【风宇冲】图形化调试 http://blog.sina.com.cn/s/blog_471132920101gxzf.html 这里可耻的转载一下
这里根据我自己的要求,只要能在Editor模式下的Scene和Game中显示就可以了。 2、Unity如何绘制网格 在1中 大牛已经给出了方向和简单的列子,下面就是自己实现了,刚开始比较懒,还是想一步到位,直接找到一个类似DrawRect的函数直接在中绘制矩形,结果果然失败,找了很久也没有这样的函数和或者别人分享的。下面分享下自己搜集的方案 A、使用Mesh网格进行绘制 说实话我觉得这种方法对于我的需求是没什么实际作用的,而且看起来有些虚,最主要的问题是网格不可控制。
[C#]
纯文本查看
复制代码
B、第二个方法就是使用GL 这种方法其实还是比较底层的,竟然还用到了传说中的Shader,用于拔高也是不错的列子,而且看起来也不虚,但最主要的问题是网格不可控制。再说我也觉得用GL有点杀鸡用牛刀的感觉。
[C#]
纯文本查看
复制代码
C、第三个方法Gizmos.Draw 这也是我最终使用的方法,实现效果如下所示,其实Gizmos的功能很强大,可以绘制Mesh和Cude,在3D调试中用处不能小视。 这里主要遇到的问题是Gizmos没有提供DrawRect函数需要自己实现,这里其实本身没有什么技术难度,因为已经提供了DrawLine函数。自己比较懒,本来想看是否有现成的直接剽窃下,后来Seach未果,只能自己实现了,下面是实现函数,同时提供DrawPath和DrawLine函数这里是从itween里提取出来的
[C#]
纯文本查看
复制代码
总结程序员都懒总想找现成的,这次我提供个现成的给你哦。如果真对你有用别忘记给我投一票。 2016年度游戏蛮牛最受欢迎专栏作家评选,为他们投票! 别忘记我是恶魔猎手哦(wind2006) |