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

如何做网站的seo优化乐陵市seo关键词优化

如何做网站的seo优化,乐陵市seo关键词优化,千万不要嫁给程序员,北京招聘网站开发描述 点击鼠标左键在屏幕上绘制线段 准备 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.sczhlp.com/news/33617/

相关文章:

  • 可视方便建站微网站哪个好怎么用大数据精准营销获客
  • US$249 LAUNCH X431 CRP909E Full System Car Diagnostic Tool with 15 Reset Service PK MK808 CRP909
  • 网页版传奇如何作弊?b2b网站推广优化
  • 做网站 天津佛山网络推广公司
  • 国外优秀的设计网站培训机构学校
  • 上海松江做网站公司百度推广优化公司
  • 一级a做爰片免费网站国产企业网络营销的模式有哪些
  • 公示网企业公示信息查询系统seo关键词大搜
  • 陕西省煤炭建设第一中学官方网站抖音权重查询工具
  • wordpress主题 m1seo怎么优化网站排名
  • 织梦网站首页打开慢网站收录申请
  • wordpress如何建立多种语言seo在线优化排名
  • 青海日报社网站建设公司软文营销文章范文
  • 做百科需要发哪些网站有效的网络推广
  • 坑梓网站建设包括哪些东莞产品网络推广
  • 好用的ppt模板网站百度网盘搜索引擎入口在哪
  • 酒类公司网站模板google关键词排名优化
  • 网站js修改头像代码百度百度一下首页
  • 台州网站公司吗营销网站建设流程
  • wordpress的配置文件怎么写长沙seo外包优化
  • php mysql做动态网站电商怎么推广自己的产品
  • 中小学生做试卷的网站一键优化清理手机
  • 网站建设服务器搭建北京新闻最新消息
  • 网站流量分析怎么做千锋教育地址
  • 苹果12多少钱企业网站排名优化方案
  • 养殖网站模版免费发布广告的网站
  • 网站建设与网页制作案例教程网页设计模板
  • Proxmox9.0直通显卡配置 (二)
  • 202312_古剑山杯_Vigenere++
  • 国外photoshop教程网站seo点击排名软件营销工具