位置: 编程技术 - 正文

小地图的实现与远近景的切换(小地图的主要作用是观察队友的大概位置)

编辑:rootadmin
/// <summary>/// Minimap camera./// This script use to control minimap camera/// </summary>using UnityEngine;using System.Collections;public class MinimapCamera : MonoBehaviour {public static int zoomLevel; //zoom levelpublic static MinimapCamera Instance; //declare this to global script//Private variableprivate int zoomCurrent;[HideInInspector]public Transform Target;void Start(){//Setting Default Value//zoomLevel与zoomCurrent 控制小地图视角的缩放zoomLevel = 3;zoomCurrent = zoomLevel;//实现摄像机跟随主角Instance = this;GameObject hero;hero = GameObject.FindGameObjectWithTag("Player");//Target 为Player Target = hero.GetComponent<Transform>();}// Update is called once per framevoid Update () {//Follow player//摄像机获取player的坐标,实现小地图的摄像机跟随效果;transform.position = new Vector3(Target.position.x,transform.position.y,Target.position.z);ZoomManage ();}//控制小地图的最大和最小缩放程度;void ZoomManage (){//Check zoom limit// 当zoomLevel 小于0时,将其&#;设为0,控制在最小缩放的&#;为0if(zoomLevel < 0){zoomLevel = 0;}else if(zoomLevel > 4){zoomLevel = 4;}}//通过zoomLevel&#;得大小 来控制小地图视角大小的缩放,当zoomLevel小于zoomCurrent时,说明地图要缩小,此时相机的orthographicSize&#;要增加;public void ZoomUpdate(){if(zoomLevel < zoomCurrent){this.GetComponent<Camera>().orthographicSize &#;= 3;zoomCurrent = zoomLevel;}else// 当zoomLevel大于zoomCurrent时,说明地图要放大,此时相机的orthographicSize&#;要缩小;if(zoomLevel > zoomCurrent){this.GetComponent<Camera>().orthographicSize -= 3;zoomCurrent = zoomLevel;}}}

推荐整理分享小地图的实现与远近景的切换(小地图的主要作用是观察队友的大概位置),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:小地图的实现与运用,小地图是什么意思,小地图的实现与设计,什么是小地图,小地图绘制,小地图的主要作用,小地图的实现与运用,小地图的实现与实践,内容如对您有帮助,希望把文章链接给更多的朋友!

小地图的实现与远近景的切换(小地图的主要作用是观察队友的大概位置)

/// <summary>/// Minimap./// This script use to call minimap on top-right screen/// </summary>using UnityEngine;using System.Collections;public class Minimap : MonoBehaviour {private Vector2 defaultScreenRes; //Screen Resolution[System.Serializable]public class GUISetting{public Vector2 position;public Vector2 size;public Texture2D[] texture;}[System.Serializable]public class LabelSetting{public Vector2 position;public GUIStyle labelStyle;}[System.Serializable]public class MinimapSetting{public Vector2 position;public Vector2 size;public Texture texture;public Material renderMaterial;}[System.Serializable]public class ButtonSetting{public Vector2 position;public Vector2 size;public GUIStyle buttonStlye;}public GUISetting frameMap,mapNameBar; //GUI settingpublic MinimapSetting minimap; //Minimap settingpublic LabelSetting mapName; //Map name setting//引用 ButtonSetting 类,所有的图标都在 ButtonSetting里实实例化,在这个类里加载到界面;public ButtonSetting zoomInBt,zoomOutBt; //button setting// Use this for initializationvoid Start () {defaultScreenRes.x = ; //declare max screen ratiodefaultScreenRes.y = ; //declare max screen ratio}void OnGUI (){if(!GameSetting.Instance.hideMinimap){// Resize GUI Matrix according to screen size ResizeGUIMatrix();//Draw MinimapGraphics.DrawTexture(new Rect(minimap.position.x,minimap.position.y,minimap.size.x ,minimap.size.y),minimap.texture,minimap.renderMaterial);//Draw MinimapFrameGUI.DrawTexture(new Rect(frameMap.position.x,frameMap.position.y,frameMap.size.x,frameMap.size.y),frameMap.texture[0]);//Draw Map name barGUI.DrawTexture(new Rect(mapNameBar.position.x,mapNameBar.position.y,mapNameBar.size.x,mapNameBar.size.y),mapNameBar.texture[0]);TextFilter.DrawOutline(new Rect(mapName.position.x ,mapName.position.y, , ),Application.loadedLevelName,mapName.labelStyle,Color.black,Color.white,2f);//Draw zoom in button//GUI.Button():Make a single press button. The user clicks them and something happens immediately.if(GUI.Button(new Rect(zoomInBt.position.x,zoomInBt.position.y,zoomInBt.size.x,zoomInBt.size.y),"",zoomInBt.buttonStlye)){MinimapCamera.zoomLevel&#;&#;;MinimapCamera.Instance.ZoomUpdate();}//Draw zoom out buttonif(GUI.Button(new Rect(zoomOutBt.position.x,zoomOutBt.position.y,zoomOutBt.size.x,zoomOutBt.size.y),"",zoomOutBt.buttonStlye)){ //zoomLevel 减小,小地图视角要缩小;MinimapCamera.zoomLevel--;MinimapCamera.Instance.ZoomUpdate();}// Reset matrix after finish GUI.matrix = Matrix4x4.identity;}else{this.enabled = false;}}void ResizeGUIMatrix() { // Set matrix Vector2 ratio = new Vector2(Screen.width/defaultScreenRes.x , Screen.height/defaultScreenRes.y ); Matrix4x4 guiMatrix = Matrix4x4.identity; guiMatrix.SetTRS(new Vector3(1, 1, 1), Quaternion.identity, new Vector3(ratio.x, ratio.y, 1)); GUI.matrix = guiMatrix; }}

【unity资源管理】内存池 内存池思想:创建对象时,先检查内存池中是否有缓存对象,如果没有再创建新的。删除对象时,不立即销毁,缓存一段时间,避免重复创建,提升执

编辑器拓展 Menuitem usingUnityEngine;usingSystem.Collections;usingUnityEditor;publicclassMyEditorWindow:EditorWindow{[MenuItem(Window/MyWindow)]staticvoidAddWindow(){//创建窗口Rectrect=newRect(0,0,,);MyEditorWi

编辑器拓展 CustomEditor usingUnityEngine;usingSystem.Collections;usingUnityEditor;//自定义样式的脚本[CustomEditor(typeof(CubeScript))]publicclassEditorTest:Editor{//自定义Inspector视图publicoverridevoidOnInspect

标签: 小地图的主要作用是观察队友的大概位置

本文链接地址:https://www.jiuchutong.com/biancheng/369359.html 转载请保留说明!

上一篇:Unity2D Sprite 描边Shader(unity描边shader)

下一篇:【unity资源管理】内存池(unity项目中的资源)

  • 所得税报表的营业成本包括管理费用吗
  • 培训机构开发票不能开公司抬头吗
  • 应纳税所得额超过36000至144000
  • 税款状态已缴款未入库
  • 个税手续费返还属于政府补助吗
  • 企业所得税季度申报
  • 单位和职工个人缴费基数如何确定的规定
  • 临时聘用人员费用谁承担
  • 民办幼儿园提供什么服务
  • 机动车销售统一专票可以抵扣进项税额吗
  • 资产负债表预收预付账款怎么填
  • 经济合同
  • 营改增后销售租赁后的设备如何做税务处理?
  • 超市送现金券怎么做账
  • 固定资产认证进项在勾选平台勾吗
  • 资产减值损失和信用损失的区别
  • 增值税发票过期了,对方可以重开吗
  • 卷式发票有税率吗
  • 关于住宿费增值税专发票抵扣问题
  • 公休假补贴多少钱
  • 所有的固定资产都有残值率吗
  • 工商年报报表
  • 无车承运人增值税
  • 亏损的递延所得税怎么理解
  • 发生的费用可以直接计入主营业务成本吗
  • 股权并购和资产的关系
  • 个人租房给公司开票税点
  • 股权收购特殊性税务处理案例
  • 华为手机屏幕变成黑白怎么调回来
  • php数组函数有哪些
  • PHP:curl_multi_setopt()的用法_cURL函数
  • 2017年8月21日是什么日子
  • PHP:imagestringup()的用法_GD库图像处理函数
  • win7系统任务计划在哪里
  • 二手房转让中转什么意思
  • 若依框架是什么框架
  • 外币交易是什么意思
  • nginx同一个端口设置两个网站
  • laravel 5.4中实现无限级分类的方法示例
  • 非上市公司股权估值
  • thinkphp配置文件
  • 前端面试题什么是网络协议
  • vue3生命周期及使用
  • 本年利润有余额是什么意思
  • 股东可以领取工资吗
  • sqlserver控制台
  • 增值税税负率是多少
  • 盈余公积的计提基数
  • 公司收到服务费要交哪些税
  • 国有土地使用权是什么意思
  • 我国耕地占用税使用的税率为
  • 定货还是订货
  • 土地勘测费收费标准
  • 标的编制费
  • 购买的银行理财产品能提前赎回吗
  • 存在弃置费用的固定资产例题
  • mysql in如何优化
  • win10禁用windows键
  • 一键ghost U盘版
  • centos和rhel
  • bearshare.exe进程安全吗 bearshare是什么进程
  • windows2008和win8
  • 怎么在win7开始菜单添加文件夹
  • rcapi.exe - rcapi是什么进程 有什么用
  • fciv.exe
  • 如何将win10系统从c盘迁移到d盘
  • win7升级到win10有无影响
  • vsftpd教程
  • [置顶]bilinovel
  • 很实用的话
  • 实现点击下箭头的方法
  • 搭建nodejs
  • 为什么使用json传输数据
  • nodejs+websocket实时聊天系统改进版
  • js 实现ajax
  • python电话本
  • javascript总结
  • 申报参保时间怎么填
  • 票据贴现的票据是什么
  • 广东税务微信公众号微办税
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设