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

网站建设的招聘要求手机app定制开发多少钱

网站建设的招聘要求,手机app定制开发多少钱,信息港官网,贵州建设厅施工员考试网站描述 点击鼠标左键在屏幕上绘制线段 准备 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/87525/

相关文章:

  • 易语言做网站视频佛山做外贸网站的公司吗
  • 湖北网站建设贴吧西安高新区网站制作
  • 云梦做网站做婚庆网站的想法
  • 做彩票网站代理犯法吗上海崇明林业建设有限公司网站
  • 班级同学录网站建设公司可以网上注册吗
  • dw怎么做网站后台wordpress汉化制作
  • 牙克石网站建设搜索网站开发背景
  • 百度网站的网址南通公司建站模板
  • 中文网站编辑青岛品牌网站建设
  • 山西免费网站关键词优化排名项目建设表态发言
  • 怎么做虚拟的网站网站服务器搬迁
  • 手机手机网站制作网络免费推广网站
  • 珠海企业网站建设公司wordpress pin
  • phpcms v9 网站模板seo发展现状
  • 手表网站素材成都网站优化外包
  • 杭州专门做网站衣服 div网站
  • 模板网站的弊端重庆铜梁网站建设报价
  • discuz 做的网站科技公司注册需要什么条件
  • 网站是如何做的湖南营销型网站建设磐石网络
  • 北京怎样做企业网站门户网站建设培训简报
  • 网站数据库有哪些菏泽做网站优化的
  • 百度行业网站怎么做宁波专业网站推广平台便宜
  • 企业网站制作是什么长沙建设工程造价网
  • 卖酒网站排名wordpress存档
  • 十大高端网站定制设计师个人公众号登录平台
  • 怎么做企业营销型网站济南网站建设公司熊掌号
  • 课件ppt模板免费下载网站购物网站模块例子
  • 岳池网站建设2345网址导航站
  • 尚品网站建设建设公司的网站制作
  • 信息型网站建设的目的定位房产中介公司网站源码