当前位置: 首页 > 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/240421/

相关文章:

  • 做胎儿羊水鉴定网站请人做网站域名和主机
  • 好的网站建设平台关于做网站流程
  • 学校网站建设及管理制度找外包公司做网站给源码吗
  • 没有网站 可以做cpa泰安互联网公司有哪些
  • 网站怎么设计制作wordpress 阅读器
  • 想做一个网站怎么做的中国企业500强利润排行
  • wordpress网站设密码网页链接 提取码:qqcd
  • 做一个小网站需要多少钱做网站如何挑选服务器
  • 精品购物网站网络营销外包专家
  • 做网页到哪个网站找素材页面设计原型图
  • 放单网站搜索引擎优化的定义是什么
  • asp.net企业网站模板网站建设和维护
  • 建立网站免费wordpress数据库导入插件
  • iis做的网站如何添加播放器怎么在建设银行网站购买国债
  • 广西城乡住房建设厅网站kol推广
  • 建网站的流程及注意事项帮别人设计网站的网站吗
  • 郓城县城乡和建设局网站08网站建设
  • 网站优化建议怎么写宿州市埇桥建设规划局网站
  • 企业网站优化分为哪两个方向学编程的费用一般是多少
  • 张家港网站哪家做的好公司网站背景图片
  • 网站制作制作公司郑州团购网站建设
  • 门户网站制作百度文章收录查询
  • 贵阳学网站建设柯桥建设局网站
  • 网站开发图形化软件昆山网站建设怎么样
  • 做网页网站做网站为什么要买网站空间
  • phpcms网站音乐代码存放在什么位置自己做网站能赚钱吗2018
  • 芜湖网站制作网站建设光盘
  • 军博网站建设如何做单页网站
  • c2c模式的网站有哪些设计网站printerest
  • 建筑给排水代做网站谷歌浏览器网页版入口在哪里