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

看设计比较好的网站百度搜索风云榜单

看设计比较好的网站,百度搜索风云榜单,提高网站目标流量,全球设计师网描述 点击鼠标左键在屏幕上绘制线段 准备 VertexHelper 网格绘制工具类向量、叉乘RectTransformUtility.ScreenPointToLocalPointInRectangleSetVerticesDirtyOnPopulateMesh 思路 鼠标按下,记录线段起点;鼠标持续按下,记录鼠标当前帧的…

描述

点击鼠标左键在屏幕上绘制线段

准备

  1. VertexHelper 网格绘制工具类
  2. 向量、叉乘
  3. RectTransformUtility.ScreenPointToLocalPointInRectangle
  4. SetVerticesDirty
  5. OnPopulateMesh

思路

  1. 鼠标按下,记录线段起点;
  2. 鼠标持续按下,记录鼠标当前帧的移动向量;
  3. 使用叉乘获取垂直与移动向量的单位向量;
  4. 根据设置的宽度获取四个顶点;设置顶点脏数据,更新网格

示例

新建脚本,继承MaskableGraphic;
创建一个Image,移除Image组件,添加新建脚本。
脚本内容如下:

引入命名空间

using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

属性

private List<List<UIVertex>> vertexList = new List<List<UIVertex>>();//缓存线段上的网格顶点
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 = GetComponent<RectTransform>();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;List<UIVertex> ver = new List<UIVertex>();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.yayakq.cn/news/496244/

相关文章:

  • 做垂直导购网站还行吗中国制造网
  • 官方网站下载官方版本大连开发区地图全图
  • 网站内链少改怎么做恒星科技网站建设
  • 云南响应式网站建设网站建设方案doc
  • 网络调查问卷怎么制作宁波seo排名外包
  • 可以建设彩票网站吗安康电商网站建设
  • 建企业网站用什么源码wordpress后台登陆logo
  • 网站功能说明怎么做网站建设的整个过程
  • 培训行业门户网站建设县级网站建设培训会
  • 广东峰凌建设有限公司网站无锡企业如何建网站
  • 寻花问柳专注做一家男性喜欢的网站怎样网站设计
  • 网站收录没了源码编辑器
  • 微商城网站建设平台wordpress上显示pdf
  • 深圳股票配资网站开发玛伊网站做兼职加入要多少钱
  • 新乡电商网站建设团支书登录智慧团建网站
  • 手表哪个网站最好重庆有哪些科技骗子公司
  • 阿里邮箱 网站开发西安今天消息
  • 网络电子商务购物网站黑龙seo网站优化
  • 公司网站怎么建复旦学霸张立勇做的网站
  • 常熟公司网站建设电话深圳国内网站设计公司
  • 网站建设设计广州网线制作过程图片
  • 网站建设公司知乎镇江搜索优化技巧
  • 小型网站开发语言颜色选取网站
  • 移动端h5网站开发框架哪里有网站推广软件
  • 网站策划工资一般多少如何将网站上传到万网主机
  • 公司网站怎么做优化网站建设公司前台
  • 做海报的素材网站苏州电商关键词优化
  • 登录门户网站更改wordpress最大上传文件大小
  • 长沙市城市建设档案馆网站齐齐哈尔铁峰建设局网站
  • 网站建设用什么语言个人营业执照网上注销流程