位置: 编程技术 - 正文

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

编辑: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项目中的资源)

  • 公司自有房产自用要交房产税吗
  • 应收款确认坏账分录
  • 广告制作需要交文化建设费吗
  • 精创云所有者权益为负
  • 出口退税报关单解密在哪下载
  • 公司一般户走账要交税吗
  • 生育津贴做账法会计准则
  • 装卸费可以抵扣销项税额吗
  • 小微企业可以开9个点的专票吗
  • 如何下载金三系统的客户端插件?
  • 企业优惠条件
  • 企业购入新能源电车需要缴纳印花税吗
  • 外包劳务费用如何计算
  • 设定受益计划资产上限
  • 纳税能力体现的内容
  • 进项大于销项下月可不可以抵扣
  • 跨月发票冲红账怎么做
  • 固定资产报多好还是报少好
  • 民间非营利组织会计制度会计科目
  • 企业信息公示社保信息怎么填,公司没有交
  • 企业所得税纳税标准
  • 财务期初期末
  • 冲暂估成本会计分录怎么做
  • 附加税减免要计税吗
  • win10安全中心通知关闭
  • 加班车费报销计入什么科目
  • 其他业务成本主要有哪些
  • element分页器
  • 员工补偿金分录
  • vit详解
  • phpcms 还有人用吗
  • echarts-gl
  • 三维重建是啥意思
  • 直连路由,静态路由
  • 文本超出单元格
  • 如何在织梦中设置图片加文字
  • 帝国cms如何使用
  • 实际缴纳的增值税是什么意思
  • 生产销售库存的会计科目
  • 帝国cms好用吗
  • 出口退税转内销还是转免税好
  • sqlserver数据库获取当前时间
  • 企业利润表表怎么看
  • 小规模纳税人收入会计分录
  • 物业 收电费
  • 事业单位大型修缮与办公用房维修费区别
  • 公司找的第三方代缴社保
  • 计量差错引起的原材料盘亏
  • 长期股权投资转让会计处理
  • 计提工资时个税挂其他应收款
  • 建安企业增值税预缴
  • 厂家返利怎么入账
  • 水电费没有发票可以入账吗
  • 以前年度应收账款无法收回
  • 管理费用业务招待费包括哪些
  • 营业收入和销售收入的比值
  • 印花税怎么新增税源
  • 商品流通企业会计
  • mysql error0
  • win7开机提示由于启动计算机时出现页面文件
  • win10更新后自动锁定
  • mac装xp系统
  • win7c盘winsxs
  • linux安装yum命令步骤
  • win8系统的运行在哪
  • 如何把网址设为常用网址
  • win10系统预览版
  • linux不小心删除目录怎么恢复
  • nodejs全栈前景
  • shell脚本怎么导出
  • cmd更改文件属性
  • css回到页面顶部
  • jquery基本知识
  • 基于jquery实现小说
  • jquery 使用
  • python读取一个文件并写入另一个文件
  • 装饰装修公司需要什么
  • 中国个人所得税是多少?
  • 我的宁夏灵活就业缴费失败
  • 税控盘开电子发票流程
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设