参考官方教程:Creating A Minimap System
方法1:Github:TanksPluggableAI
方法2:Github:GentleTank
方法1:使用额外相机
这个小地图添加在上一篇中AI坦克项目上。
小地图的是实现原理很简单,就是添加多一个相机,设置垂直投影,然后将投影的画面送到显示在UI的Textrue上面。
(结果如图)

层级结构,资源文件


-
为坦克添加小图标(添加Quad,材质为带小坦克图标的MinimapIconMaterial,这样可以顺便在生成坦克的时候改变颜色),并标记为Layer为Minimap,只在小地图中显示。
image.png
image.png
-
为坦克添加跟随的相机(MinimapCamera),相机的内容就是小地图的内容。
image.png
3. 在游戏画面中添加小地图。
<a name="t6" target="_blank" style="text-decoration: none; box-sizing: border-box; color: rgb(12, 137, 207);"></a>MinimapMask,就是一个白色圆,添加遮罩。在他的子对象中,只能显示在这个圆里。

MinimapContent,地图内容,就是一张Textrue。

实际结果:在主相机中不显示minimap Layer的东西(坦克图标)、在小地图中只显示坦克图标和静态场景,及不显示坦克、子弹、粒子等等。


方法2:计算相对位置(类似雷达)

说明:右上角为小地图,每个有颜色的圆点代表一个坦克,正中心的是玩家。
原理:就是先设定代表玩家坦克的圆点,再通过计算玩家坦克与其他坦克距离,按比例绘制其他圆点在小地图上。
网友评论