Unity 小地图 之 使用UGUI实现小地图二功能实现

2025-05-20 00:52:37

Unity 小地图 之 使用UGUI实现小地图二功能实现。本节介绍在布置好的剑钕饿粪场景(场景布置可以参见下面的经验链接)里面墩伛荨矧通过“UGUI”和“Render Texture”的联合使用,实现小地图的简单案例,具体如下

工具/原料

Unity

UGUI

Render Texture

一、知识要点

1、RenderTexture:Inherits from:TextureRender textures are textures that can be rendere颊俄岿髭d to.They can be used to implement image based rendering effects, dynamic shadows, projectors, reflections or surveillance cameras.One typical usage of render textures is setting them as the "target texture" property of a Camera (Camera.targetTexture), this will make a camera render into a texture instead of rendering to the screen.Keep in mind that render texture contents can become "lost" on certain events, like loading a new level, system going to a screensaver mode, in and out of fullscreen and so on. When that happens, your existing render textures will become "not yet created" again, you can check for that withIsCreatedfunction.As with other "native engine object" types, it is important to pay attention to the lifetime of any render textures and release them when you are finished using them with theReleasefunction, as they will not be garbage collected like normal managed types.

2、方法提要:1)摄像机渲染图片“Render Texture”;2)在UGUI的“RawImage”上呈现摄像机渲染图片“Render Texture”;

二、小地图 之 使用UGUI实现小地图二功能实现

1、在工程中新建一个“Render Texture”,命名为“MiniMapRenderTexture”,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

2、把“MiniMapRenderTexture”,赋给“MiniMapCamera”的“Target Texture”进行渲染,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

3、在工程中新建一个“Image”和子“RawImage”,并把“Image”的“Source Image”附图“Knob”,且添加上“Mask”遮罩组件,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

4、把“MiniMapRenderTexture”赋值给“RawImage”的“Texture”,,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

5、调整好UGUI的UI布局,即可在UI上看到小地图的功能效果,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

6、小地图上的图标较小,可以选中“Quad”把他们的比例改为2,效果会较好一点,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

7、运行长中,即可看到场景中,主摄像机不渲染“Player”和“Enemy”的小图标,小地图不渲染“Player”和“Enemy”实体,具体如下图

Unity 小地图 之 使用UGUI实现小地图二功能实现

8、在实际应用中可以把“MiniMapCamera”实时跟随主角移动,就实现动态小地图的效果了

9、到此,《Unity 小地图 之 使用UGUI实现小地图二功能实现》讲解结束,谢谢

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢