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

家教网站开发数据分析平台

家教网站开发,数据分析平台,时代创信网站设计 北京,WordPress支持api吗思路-绘制空心矩形 拓展UGUI的Graphic类,实现拖拽接口。 开始拖拽时记录鼠标位置, 使用拖拽中的鼠标位置和记录的位置,计算矩形顶点,绘制矩形。 两个三角形合并为一个矩形,作为空心矩形的一条边,四个边合并为空心矩形…

思路-绘制空心矩形

拓展UGUI的Graphic类,实现拖拽接口。
开始拖拽时记录鼠标位置,
使用拖拽中的鼠标位置和记录的位置,计算矩形顶点,绘制矩形。
两个三角形合并为一个矩形,作为空心矩形的一条边,四个边合并为空心矩形。

示例-绘制空心矩形

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;public class TestDraw : Graphic, IBeginDragHandler, IDragHandler, IEndDragHandler
{UIVertex[] rectangle1 = new UIVertex[4];UIVertex[] rectangle2 = new UIVertex[4];UIVertex[] rectangle3 = new UIVertex[4];UIVertex[] rectangle4 = new UIVertex[4];[SerializeField] float width = 5f;Vector3 lastPoint;protected override void Awake(){Init(rectangle1);Init(rectangle2);Init(rectangle3);Init(rectangle4);void Init(UIVertex[] uIVertices){var length = uIVertices.Length;for (int i = 0; i < length; i++)uIVertices[i] = new UIVertex();}}protected override void OnPopulateMesh(VertexHelper vh){vh.Clear();vh.AddUIVertexQuad(rectangle1);vh.AddUIVertexQuad(rectangle2);vh.AddUIVertexQuad(rectangle3);vh.AddUIVertexQuad(rectangle4);}public void ClearDraw(){Clear(rectangle1);Clear(rectangle2);Clear(rectangle3);Clear(rectangle4);void Clear(UIVertex[] uIVertices){var length = uIVertices.Length;for (int i = 0; i < length; i++)uIVertices[i].position = Vector3.zero;}SetVerticesDirty();}public void OnBeginDrag(PointerEventData eventData){lastPoint = ScreenPointToLocalPoint(rectTransform, eventData.position);}public void OnDrag(PointerEventData eventData){Vector3 point = ScreenPointToLocalPoint(rectTransform, eventData.position);if (lastPoint.x < point.x && lastPoint.y < point.y)//起点在左下角{//水平方向投影向量           var horizontalNormal = Vector3.Project(point - lastPoint, Vector3.right);SetRectangleVertex(point - horizontalNormal, point, lastPoint + horizontalNormal, lastPoint);SetRectangleColor(color);SetVerticesDirty();}else if (lastPoint.x > point.x && lastPoint.y > point.y)//起点在右上角{var horizontalNormal = Vector3.Project(point - lastPoint, Vector3.right);SetRectangleVertex(lastPoint + horizontalNormal, lastPoint, point - horizontalNormal, point);SetRectangleColor(color);SetVerticesDirty();}else if (lastPoint.x > point.x && lastPoint.y < point.y)//起点在右下角{var horizontalNormal = Vector3.Project(point - lastPoint, Vector3.right);SetRectangleVertex(point, point - horizontalNormal, lastPoint, lastPoint + horizontalNormal);SetRectangleColor(color);SetVerticesDirty();}else if (lastPoint.x < point.x && lastPoint.y > point.y)//起点在左上角{var horizontalNormal = Vector3.Project(point - lastPoint, Vector3.right);SetRectangleVertex(lastPoint, lastPoint + horizontalNormal, point, point - horizontalNormal);SetRectangleColor(color);SetVerticesDirty();}}public void OnEndDrag(PointerEventData eventData){lastPoint = Vector3.zero;}void SetRectangleVertex(Vector3 topLeftUp, Vector3 topRigthUp, Vector3 bottomRightDown, Vector3 bottomLeftDown){//top矩形rectangle1[0].position = topLeftUp;rectangle1[1].position = topRigthUp;rectangle1[2].position = topRigthUp - Vector3.up * width;rectangle1[3].position = topLeftUp - Vector3.up * width;//bottom矩形rectangle2[0].position = bottomRightDown;rectangle2[1].position = bottomLeftDown;rectangle2[2].position = bottomLeftDown + Vector3.up * width;rectangle2[3].position = bottomRightDown + Vector3.up * width;//left矩形rectangle3[0].position = topLeftUp - Vector3.up * width;rectangle3[1].position = topLeftUp - Vector3.up * width + Vector3.right * width;rectangle3[2].position = bottomLeftDown + Vector3.up * width + Vector3.right * width;rectangle3[3].position = bottomLeftDown + Vector3.up * width;//right矩形rectangle4[0].position = topRigthUp - Vector3.up * width;rectangle4[1].position = bottomRightDown + Vector3.up * width;rectangle4[2].position = bottomRightDown + Vector3.up * width - Vector3.right * width;rectangle4[3].position = topRigthUp - Vector3.up * width - Vector3.right * width;}void SetRectangleColor(Color color){var length = rectangle1.Length;for (int i = 0; i < length; i++)rectangle1[i].color = color;length = rectangle2.Length;for (int i = 0; i < length; i++)rectangle2[i].color = color;length = rectangle3.Length;for (int i = 0; i < length; i++)rectangle3[i].color = color;length = rectangle4.Length;for (int i = 0; i < length; i++)rectangle4[i].color = color;}Vector2 ScreenPointToLocalPoint(RectTransform rect, Vector2 mousePoint){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;}void Update(){if (Input.GetKeyDown(KeyCode.Space))ClearDraw();}
}

场景结构

在这里插入图片描述
TestDraw对象挂载TestDraw脚本,该对象需要CanvsRenderer脚本,大小为屏幕大小

运行结果

在这里插入图片描述
上方为矩形网格
运行,拖拽鼠标显示矩形。
按下空格键,清除矩形。

知识点

三角形的绘制需要三个顶点,三角形使用顺时针的顺序进行绘制。

其他几何图形的绘制思路

线:多个矩形组合而成
箭头:一个三角形,一个矩形组合而成。
空心椭圆:获取两个圆上的顶点,按照顺序绘制三角形。
椭圆绘制思路:已知圆心,半径
将圆划分多份,利用三角函数和弧度获取x坐标,y坐标。
将x,y坐标缩放,可得到椭圆上的点。

http://www.dtcms.com/wzjs/105340.html

相关文章:

  • 嘉定专业网站建设长沙百度seo代理
  • 网络构建是什么标题seo是什么意思
  • 专做海外代购的网站关键词排名优化公司哪家强
  • 电子商务网站网站建设网络培训心得体会5篇
  • 沧州做网站价格杭州网站设计
  • 苏州公司注册查询seo对网店推广的作用有哪些
  • 申请网站域名多少钱打开百度官网
  • 郑州百度网站快速优化年度关键词有哪些
  • 新手如何优化网站排名百度云搜索
  • 烟台模板建站代理四川刚刚发布的最新新闻
  • 应急管理部政府网站建设依据佛山今日头条
  • 云南省建设厅一级建造师网站十大接单推广平台
  • 网站如何做压力测试我国网络营销现状分析
  • 做网站的功能是什么小网站怎么搜关键词
  • 石狮市住房和城乡建设局网站免费开网店免费供货
  • 兰州装修公司口碑排名推荐罗湖区seo排名
  • 网站建设服务合同缴纳印花税吗域名注册网站
  • 网站运营及推广方案百度推广关键词匹配模式
  • 设计公司logo图片外贸推广优化公司
  • 手机wap网站大全重大新闻事件
  • 郑州金水区网站建设宁波seo教程app推广
  • 网站开发行业前景谷歌官方网站首页
  • 戚墅堰常州做网站网络营销的公司有哪些
  • 网站欢迎页面flash百度seo排名软件
  • 网站建设哪里找软文营销方法有哪些
  • 网页兼容性站点电商培训大概多少学费
  • 一级域名二级域名哪个好湖南靠谱关键词优化
  • 花钱做的网站本人可以关闭吗百度提交入口地址在哪
  • 免费app做logo的网站seo网站有优化培训吗
  • wordpress输出tagsseo助手