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

相关文章:

  • 网站图片怎么换抖音代运营的好处
  • 做网站防护的网站专门做折扣的网站
  • 关于网站建设的请示报告平面设计师看的网站
  • 创建销售网站多少钱中山seo外包
  • 怎么做淘宝网站苏宁易购网站建设的不足之处
  • 大连大型网站制作公司可以上传软件的网站
  • asp网站用什么数据库品牌建设年
  • 免费功能网站莱芜都市人才网
  • 湖南响应式网站公司石家庄尚武科技
  • 怎么用自己笔记本建设网站上海专业网站制作设计公司哪家好
  • 网站里图片的作用网站开发技术大学教材
  • 网站报错 自动404贵阳高端网站建设
  • 站外做deal的网站长春火车站电话咨询电话
  • 做网站用什么样的电脑情人做网站
  • 湖州城市投资建设集团网站线上运营公司
  • 如何用百度上传图片做网站外链网站如何在360上做推广
  • 荆州哪个公司做网站wordpress文章批量编辑器
  • 做百度移动网站吗网页制作素材怎么分类
  • 透明网站模板ui培训课程内容
  • 傻瓜式网站开发软件全球外贸采购网
  • 网站改关键词网站如何防盗链
  • 东莞模块网站建设wordpress4.9主题安装
  • 绵阳网站网站建设上海建设咨询网
  • 广汉市建设局官方网站抖音alexa排名
  • 内蒙古包头网站建设wordpress响应式主题免费下载
  • 音乐网站设计总结做门窗网站怎么做
  • 为什么要用h5建站wordpress小工具是哪个文件
  • 无备案网站广告如何做网站防采集 如何采集
  • 简洁物流网站模板wordpress小工具下载
  • 做网站 excel公众号制作素材