位置: 编程技术 - 正文

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

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

  • 期初未缴税额是什么意思
  • 金税工程是什么单位
  • 印花税是用来干吗的
  • 失业保险稳岗返还是政府补助吗
  • 成品油认证步骤
  • 开办费计入管理费用后是否要转出
  • 企业所得税前可以扣除的项目
  • 房地产企业营销设施建造费包括哪些
  • 对外投资企业利润回国意愿的政策建议
  • 企业间无偿划转会计分录
  • 制造费用属于资产类账户吗
  • 客户能把货款打给个人吗
  • 无形资产摊销起止时间
  • 一般纳税人租赁费的税率是多少
  • 多计费用以前年度损益调整
  • 外币应收帐款汇兑损益现流附表
  • 没有对公账户的公司怎么注销
  • 财政拨款进项税怎么处理
  • 个体工商户税收标准2023年
  • 企业偷税漏税行为诉讼有效期限
  • 亏损企业是否可以上成长板
  • 固定资产报废处理流程图
  • win7系统无法启用网络发现
  • 网络端口被占用怎么解决
  • 营业外收入怎么做会计凭证
  • 废料收入应如何确定
  • 公司车过户给个人流程
  • 文化事业建设费2023年是否减免了
  • 发生利息收入的分录
  • 劳务公司的账务怎么做账
  • windows11 怎么更新
  • deepin 设置
  • macos10.15.7
  • php中??
  • 贷款损失准备的会计核算
  • 私车公用维修费属于个人承担吗
  • 员工冲借款应该怎么做账
  • 期间费用核算内容包括
  • torch.save用法
  • 工会筹备金计税依据
  • 小程序uniacid
  • 2023年最全盘点 | 16款跨平台应用程序开发框架
  • ICLR2023《Crossformer: Transformer Utilizing Cross-Dimension Dependency for Multivariate Time Series》
  • 人工智能机器人的好处
  • php递归函数桃子一天吃一半
  • 异地预缴印花税是否可以抵扣
  • 留购价计入什么费
  • 结构性存款随时可取么
  • 单位购日用品计提折旧吗
  • 缴纳上年汇算清缴的分录
  • 拆迁补偿收入是否缴纳所得税
  • 法人与财务负责人不应为同一人
  • 生活服务的行业
  • 存量资金会计处理办法
  • 应付账款周转次数计算
  • 固定性制造费用能量差异公式
  • 境外所得抵免限额大于境外承担的所得税税额
  • 免税蔬菜税额用什么表示
  • 如何远程连接小米摄像头
  • Win9传闻汇总:通知中心+免费下载+手势功能等
  • win8怎么禁止开机启动项
  • centosuuid
  • centosip配置
  • 使用标准用户帐号的方法
  • win7系统搜索在哪
  • win10系统如何屏蔽弹窗广告
  • windows7如何启动任务管理器
  • window10桌面日历
  • opengl示例
  • vuejs环境搭建
  • node的全局变量有哪些
  • sdk有问题
  • 安卓模拟器错误怎么办
  • java教程 视
  • 税务疑点核查报告
  • 关注龙江医保
  • 国地税改革意义
  • 税控盘换新会影响旧盘数据吗
  • 劳保费如何入账
  • 土地 荒
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设