当前位置: 首页 > news >正文

桐城网站定制苏州网建公司

桐城网站定制,苏州网建公司,小说盗版网站怎么做,企业网站建设都需要什么准备描述 点击鼠标左键在屏幕上绘制线段 准备 VertexHelper 网格绘制工具类向量、叉乘RectTransformUtility.ScreenPointToLocalPointInRectangleSetVerticesDirtyOnPopulateMesh 思路 鼠标按下#xff0c;记录线段起点#xff1b;鼠标持续按下#xff0c;记录鼠标当前帧的…描述 点击鼠标左键在屏幕上绘制线段 准备 VertexHelper 网格绘制工具类向量、叉乘RectTransformUtility.ScreenPointToLocalPointInRectangleSetVerticesDirtyOnPopulateMesh 思路 鼠标按下记录线段起点鼠标持续按下记录鼠标当前帧的移动向量使用叉乘获取垂直与移动向量的单位向量根据设置的宽度获取四个顶点设置顶点脏数据,更新网格 示例 新建脚本继承MaskableGraphic 创建一个Image,移除Image组件添加新建脚本。 脚本内容如下 引入命名空间 using UnityEngine; using UnityEngine.UI; using System.Collections.Generic;属性 private ListListUIVertex vertexList new ListListUIVertex();//缓存线段上的网格顶点 private Vector3 lastPoint;//上一帧的点击点 private Vector3 lastLeftPoint; private Vector3 lastRightPoint; bool isNewLine;//绘制新的线段 [SerializeField] private float lineWidth 4f;//线段宽度方法 绘制网格 protected override void OnPopulateMesh(VertexHelper vh)//绘制网格 {vh.Clear();for (int i 0; i vertexList.Count; i)vh.AddUIVertexQuad(vertexList[i].ToArray()); }方法 屏幕坐标转为本地坐标 Vector2 ScreenPointToLocalPoint(Vector2 mousePoint) {var Rect GetComponentRectTransform();Vector2 result Vector2.zero;switch (canvas.renderMode){case RenderMode.ScreenSpaceOverlay:RectTransformUtility.ScreenPointToLocalPointInRectangle(Rect, mousePoint, null, out result);break;case RenderMode.ScreenSpaceCamera:RectTransformUtility.ScreenPointToLocalPointInRectangle(Rect, mousePoint, canvas.worldCamera, out result);break;case RenderMode.WorldSpace:RectTransformUtility.ScreenPointToLocalPointInRectangle(Rect, mousePoint, canvas.worldCamera, out result);break;}return result; }方法 设置网格顶点 private void Update() {if (Input.GetMouseButtonDown(0))//按下鼠标坐标表示 绘制新的线段{lastPoint ScreenPointToLocalPoint(Input.mousePosition);//屏幕点转换到当前recttransform上的点isNewLine true;vertexList.Clear();//清除上一次绘制的线段 若要保留 可不清除}else{if (Input.GetMouseButton(0)){Vector3 currentPoint ScreenPointToLocalPoint(Input.mousePosition);Vector3 dir currentPoint - lastPoint;//移动向量if (dir.magnitude 10)//移动量过小 不绘制网格return;Vector3 normal Vector3.Cross(dir.normalized, transform.forward);//移动向量和当前ui的朝向 进行叉乘if (isNewLine){isNewLine false;lastLeftPoint lastPoint normal * lineWidth;//绘制新的线段时 作为左侧起点lastRightPoint lastPoint - normal * lineWidth;}Vector3 leftPoint currentPoint normal * lineWidth;//当前线段的左侧终点Vector3 rightPoint currentPoint - normal * lineWidth;ListUIVertex ver new ListUIVertex();UIVertex uIVertex new UIVertex();//网格顶点列表uIVertex.position lastLeftPoint;uIVertex.color color;ver.Add(uIVertex);UIVertex uIVertex2 new UIVertex();uIVertex2.position lastRightPoint;uIVertex2.color color;ver.Add(uIVertex2);UIVertex uIVertex3 new UIVertex();uIVertex3.position rightPoint;uIVertex3.color color;ver.Add(uIVertex3);UIVertex uIVertex4 new UIVertex();uIVertex4.position leftPoint;uIVertex4.color color;ver.Add(uIVertex4);vertexList.Add(ver);lastLeftPoint leftPoint;//更新起点 当前帧的终点作为下一帧的起点lastRightPoint rightPoint;lastPoint currentPoint;SetVerticesDirty();//设置顶点脏数据 更新网格}} }
http://www.w-s-a.com/news/759987/

相关文章:

  • 现在建网站可以拖拉式的吗中国国内最新新闻
  • phpstorm网站开发产品logo设计
  • 电子商务网站建设与运营什么是单页面网站
  • 西安优化网站公司南阳微信网站
  • 购物网站线下推广方案佛山快速建站哪家服务专业
  • 临沂网站排名外贸网站推广方法之一
  • 手机网站百度关键词排名查询吕梁网站制作吕梁安全
  • 做网站媒体wordpress管理员账号数据库添加
  • php如何自己做网站wordpress怎么修改编辑代码
  • 网站建网站建设公司WordPress互联
  • 泊头市网站建设价格wordpress导航菜单位置
  • 怎么设立网站赚广告费网页制作素材模板图片
  • 做班级网站的目的网站设计制作公司需要什么资质
  • 济南做网站哪家好财政网站平台建设不足
  • php网站建设招聘网站开发与设计论文
  • 上海 网站建设平台 补贴网站开发招标文件范本
  • 延安网站建设公司电话手机上那个网站做农产品推广比较好
  • 增城哪家网站建设好如何做网站实名认证
  • 常州地区做网站个人购物网站需要备案吗
  • 网站建设公司 跨界鱼科技专业做服务器的网站都有哪些
  • 欧洲网站服务器网站建设费用计入什么科目
  • 网站的色调苏州策划网站模板建站公司
  • 怎么看网站用的什么后台公路建设项目可行性研究报告编制办法哪个网站查最新版
  • 可以看的网站的浏览器有哪些专业APP客户端做网站
  • 如何做网站推广自己的产品推荐个网站好吗
  • 网站经营范围wordpress注入点
  • 学校网站开发协议夫妻网络网站建设
  • 福州网站seo推广优化微信商家小程序怎么弄
  • 免费网站推广工具在游戏网站做中介合法
  • 网站建设前的规划网站建设公司六安