unity 快速创建小地图
来源:互联网 发布:好用的隔离霜 知乎 编辑:程序博客网 时间:2024/05/17 05:50
先写一个纹理遮罩shader
Shader "Unlit/TexMask"{Properties{_MainTex ("Texture", 2D) = "white" {}_MaskTex("Mask Texture",2D) = "white"{}}SubShader{Tags {"Queue"="Transparent" "RenderType"="Transparent" }LOD 100Pass{Blend SrcAlpha OneMinusSrcAlphaCGPROGRAM#pragma vertex vert#pragma fragment frag// make fog work#pragma multi_compile_fog#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;UNITY_FOG_COORDS(1)float4 vertex : SV_POSITION;};sampler2D _MainTex;float4 _MainTex_ST;sampler2D _MaskTex;v2f vert (appdata v){v2f o;o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);o.uv = TRANSFORM_TEX(v.uv, _MainTex);UNITY_TRANSFER_FOG(o,o.vertex);return o;}fixed4 frag (v2f i) : SV_Target{// sample the texturefixed4 col = tex2D(_MainTex, i.uv)*tex2D(_MaskTex,i.uv);// apply fogUNITY_APPLY_FOG(i.fogCoord, col);return col;}ENDCG}}}
原理就是:初始图片*遮罩图片,需要隐藏的地方,遮罩图片的alpha值为0,需要显示的地方为白色,这里我设置的是一张圆形遮罩,后面就是一张圆形的小地图
2.写一个小地图脚本,用来显示小地图,原理就是在目标头上生成一个摄像机,让摄像机跟随目标,并将看到的俯视图转为小地图的纹理
using UnityEngine;using UnityEngine.UI;using System.Collections;public class MiniMap : MonoBehaviour { public Transform target; private Camera miniMapCamera; private RenderTexture renderTex; public Image miniMapTex;// Use this for initializationvoid Start () { miniMapCamera = new GameObject("MiniMapCamera", typeof(Camera)).GetComponent<Camera>(); renderTex = new RenderTexture((int)miniMapCamera.pixelWidth, (int)miniMapCamera.pixelHeight, 1); miniMapCamera.targetTexture = renderTex; miniMapTex.material.SetTexture("_MainTex", renderTex); }// Update is called once per framevoid Update () { miniMapCamera.transform.position = target.position + new Vector3(0, 30, 0); miniMapCamera.transform.LookAt(target.position); }}
3.显示小地图
4.这里功能都写得特别简单粗糙,适当在上面添加一些功能和美术,应该还是蛮好看的
0 0
- unity 快速创建小地图
- unity创建小地图
- unity 3d快速使用KGFMapSystem开发小地图
- unity小地图代码
- Unity小地图制作
- Unity小地图制作
- Unity小地图制作
- Unity小地图
- Unity 制作小地图
- 【Unity3D自学记录】插件之KGFMapSystem,小地图快速创建
- Unity游戏小地图生成
- unity小地图制作代码....
- Unity 等比映射小地图
- unity小地图的实现
- Unity插件之Kolmich(教你如何快速搭建一个完整的小地图)
- Unity插件之Kolmich(教你如何快速搭建一个完整的小地图)
- Unity 控制游戏对象,显示小地图
- unity 通过摄像机模拟实现小地图
- Android简单定位实例
- UVA 1471(p242)----Defense Lines
- studio删除项目
- c++ 阻塞队列的实现
- 基因数据处理2之ftp数据快速查找
- unity 快速创建小地图
- poj2251 搜索
- iOS项目实践之时光电影(二)
- 随口唠叨
- ubuntu 14.04开启root账户
- Problem A: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换
- Linux内核分析(三)
- leetcode:Remove Nth Node From End of List 【Java】
- Virtual Machine Server快照回去后防止掉域的解决方案