UNITY 超快速 在UNITY画网格GRID

首先,下载一个shapes插件!

为shapes插件的立刻绘画模式创建一个脚本

using Shapes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;namespace XXX
{[ExecuteAlways]public class DrawController : ImmediateModeShapeDrawer{public Camera cam;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}// called by the ImmediateModeShapeDrawer base typepublic override void DrawShapes(Camera cam){if (cam != this.cam) // only draw in the player camerareturn;using (Draw.Command(cam)){Draw.ZTest = CompareFunction.Less ; // to make sure it draws on top of everything like a HUD                                                    //Draw.Matrix = crosshairTransform.localToWorldMatrix; // draw it in the space of crosshairTransformDraw.BlendMode = ShapesBlendMode.Transparent;Draw.LineGeometry = LineGeometry.Flat2D;Draw.Thickness = 0.01f;//在这里写draw函数}}}
}

public class GridPos{public int width;public int height;private float cellSize;public Vector3 originPosition;public GridPos(int width, int height, float cellSize, Vector3 originPosition){this.width = width;this.height = height;this.cellSize = cellSize;this.originPosition = originPosition;//bool showDebug = false;//if (showDebug) {//    //TextMesh[,] debugTextArray = new TextMesh[width, height];//    for (int x = 0; x < this.width; x++) {//        for (int y = 0; y < this.height; y++) {//            //debugTextArray[x, y] = UtilsClass.CreateWorldText("", null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);//            Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);//            Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);//        }//    }//    Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);//    Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);//}}public int GetWidth(){return width;}public int GetHeight(){return height;}public float GetCellSize(){return cellSize;}public Vector3 GetWorldPosition(int x, int y){return new Vector3(x, y) * cellSize + originPosition;}public Vector3 GetWorldPosition2(int x, int y){return new Vector3(x, y) * cellSize + originPosition + new Vector3(cellSize / 2, cellSize / 2, 0);}//GetXY(worldPosition, out x, out y);public void GetXY(Vector3 worldPosition, out int x, out int y){x = Mathf.FloorToInt((worldPosition - originPosition).x / cellSize);y = Mathf.FloorToInt((worldPosition - originPosition).y / cellSize);}public List<Vector3> GetAllJustPoint(){List<Vector3> m_linePoints = new List<Vector3>();for (int x = 0; x < this.width; x++){for (int y = 0; y < this.height; y++){m_linePoints.Add(GetWorldPosition(x, y));}}return m_linePoints;}public List<Vector3[]> GetAllPoint(){List<Vector3[]> m_linePoints = new List<Vector3[]>();for (int x = 0; x < this.width; x++){for (int y = 0; y < this.height; y++){Vector3[] rows = new Vector3[2];rows[0] = GetWorldPosition(x, y);rows[1] = GetWorldPosition(x, y + 1);m_linePoints.Add(rows);Vector3[] cols = new Vector3[2];//debugTextArray[x, y] = UtilsClass.CreateWorldText("", null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);cols[0] = GetWorldPosition(x, y);cols[1] = GetWorldPosition(x + 1, y);m_linePoints.Add(cols);}}Vector3[] rows2 = new Vector3[2];rows2[0] = GetWorldPosition(0, height);rows2[1] = GetWorldPosition(width, height);m_linePoints.Add(rows2);Vector3[] cols2 = new Vector3[2];cols2[0] = GetWorldPosition(width, 0);cols2[1] = GetWorldPosition(width, height);m_linePoints.Add(cols2);return m_linePoints;}

在文件中创建这样一个脚本。

使用这句话创建一个网格

 GridPos gp1 =new GridPos((int)width, (int)height, 1, new Vector3(0.5f, 0.5f, 0) + offposition);
List<Vector3[]> m_linePoints_point = gp1.GetAllPoint();//这是要绘画出来的点

然后用下列语句添加在 DrawController 中,进行绘制:

                for (int i = 0; i < m_linePoints_point.Count; i++){//Debug.Log(m_linePoints[i][0]);Draw.Line(m_linePoints_point[i][0], m_linePoints_point[i][1], UnityEngine.Color.gray);}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/191661.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

kali学习

目录 黑客法则&#xff1a; 一&#xff1a;页面使用基础 二&#xff1a;msf和Windows永恒之蓝漏洞 kali最强渗透工具——metasploit 介绍 使用永恒之蓝进行攻击 ​编辑 使用kali渗透工具生成远程控制木马 渗透测试——信息收集 域名信息收集 黑客法则&#xff1a; 一&…

Dash 协议介绍

<?xml version"1.0" encoding"utf-8"?> <MPD xmlns"urn:mpeg:dash:schema:mpd:2011" minBufferTime"PT1.5S" type"static" mediaPresentationDuration"PT0H1M0.3S" maxSegmentDuration"PT0H0M2.0…

N-135基于springboot,vue高校图书馆管理系统

开发工具&#xff1a;IDEA 服务器&#xff1a;Tomcat9.0&#xff0c; jdk1.8 项目构建&#xff1a;maven 数据库&#xff1a;mysql5.7 系统分前后台&#xff0c;项目采用前后端分离 前端技术&#xff1a;vueelementUI 服务端技术&#xff1a;springbootmybatisredis 本项…

抖音直播招聘报白的介绍和案例

抖音直播招聘报白是指企业人力资源公司在抖音进行直播招聘时&#xff0c;需要向抖音平台提供审核申请。通过报白&#xff0c;企业或人力资源公司可以更好的获取招聘渠道和更多曝光的机会&#xff0c;同时可以提升品牌形象和知名度。报白的对象针对需要企业自招的企业和人力资源…

C++EasyX之跟随鼠标移动的小球

视频链接 跟随鼠标移动的小球 用EasyX和C实现跟随鼠标移动的小球 #include<graphics.h> #include<iostream>int main() {initgraph(1280, 720);int x 0;int y 0;BeginBatchDraw();//新建缓冲区while (true){ExMessage msg;while (peekmessage(&msg)){//信…

熬夜会秃头——beta冲刺Day7

这个作业属于哪个课程2301-计算机学院-软件工程社区-CSDN社区云这个作业要求在哪里团队作业—beta冲刺事后诸葛亮-CSDN社区这个作业的目标记录beta冲刺Day7团队名称熬夜会秃头团队置顶集合随笔链接熬夜会秃头——Beta冲刺置顶随笔-CSDN社区 一、团队成员会议总结 1、成员工作…

抓包 Hook 工具Objection

Objection简介 Objection 是一个基于 Frida 开发的命令行工具&#xff0c;它可以很方便的 Hook Java 函数和类&#xff0c;并输出参数&#xff0c;调用栈&#xff0c;返回值。支持Hook Android和IOS 因为 Objection 是基于 Frida 的所以必须先安装 Frida 然后才能安装 Objecti…

torch rnn网络中,embedding.weight会反向更新吗?

结论&#xff1a;在PyTorch中&#xff0c;如果在训练中使用了embedding层&#xff0c;那么embedding.weight会被反向更新。 这是因为在训练过程中&#xff0c;模型的参数会根据损失函数的反向传播进行更新&#xff0c;而embedding层的参数embedding.weight也是模型的一部分&am…

数据结构--堆排序

NO.1 概念 堆排序是利用堆这种数据结构而设计的一种排序算法&#xff0c;堆排序是一种选择排序&#xff0c;时间复杂度均为O(nlogn)&#xff0c;是不稳定排序。 堆是完全二叉树 NO.2 如何手写一个堆 1. 插入一个数 heap[size] x; up(size); 2. 求集合当中的最小值 heap[1…

如何制作高质量AR识别跟踪图

1.前言 现在AR已经是耳熟能详的一项技术功能&#xff0c;尤其是图像目标跟踪比较常见。为确保获得最高质量的图像目标跟踪体验&#xff0c;请确保在选择图像目标时遵循以下指导原则。 2.指导原则 1.高质量图像目标跟踪体验需要图片更多的不同细节&#xff0c;不要出现大量留白…

Pandas教程06:DataFrame.merge数据的合并处理

DataFrame.merge() 是 pandas 库中用于合并两个DataFrame数据的方法。该方法主要用于根据一个或多个键&#xff08;键可以是列名或索引&#xff09;将两个 DataFrame 连接在一起&#xff0c;这个过程类似于 SQL 中的 JOIN 操作。 #我的Python教程 #微信公众号&#xff1a;wdPy…

@RequestMapping处理请求异常

使用RequestMapping不指定请求方式&#xff0c;多种请求方式都支持。 Get格式FORM_URLENCODED Content-Typeapplication/x-www-form-urlencoded URL形式传参&#xff0c;请求体里面的内容是&#xff1a;usernamejohnexample.com&passwordsecretpassword&grant_type…

C语言之位段(详解)

C语言之位段 文章目录 C语言之位段1. 位段的介绍2. 位段的内存分配3. 位段跨平台问题4. 位段的应用5. 位段使用注意 1. 位段的介绍 位段&#xff08;bit-field&#xff09;是C语言中的一种特殊数据类型&#xff0c;它允许将一个字节分成几个部分&#xff0c;并为每个部分指定特…

OpenCV-Python:模块功能介绍

OpenCV-Python是一个基于Python的开源计算机视觉库&#xff0c;它提供了丰富的功能模块来处理图像和视频。以下是一些常用的功能模块&#xff1a; 1.cv2&#xff1a;主要包含了OpenCV库的核心功能&#xff0c;例如图像的读取、显示和保存&#xff0c;以及基本的图像处理操作。…

深入解析JVM内存结构:Metaspace、堆与垃圾收集器

&#x1f680; 作者主页&#xff1a; 有来技术 &#x1f525; 开源项目&#xff1a; youlai-mall &#x1f343; vue3-element-admin &#x1f343; youlai-boot &#x1f33a; 仓库主页&#xff1a; Gitee &#x1f4ab; Github &#x1f4ab; GitCode &#x1f496; 欢迎点赞…

SHAP(五):使用 XGBoost 进行人口普查收入分类

SHAP&#xff08;五&#xff09;&#xff1a;使用 XGBoost 进行人口普查收入分类 本笔记本演示了如何使用 XGBoost 预测个人年收入超过 5 万美元的概率。 它使用标准 UCI 成人收入数据集。 要下载此笔记本的副本&#xff0c;请访问 github。 XGBoost 等梯度增强机方法对于具有…

常见场景题-接口重试策略如何设计?

接口重试策略如何设计&#xff1f; 常见的重试策略有两种&#xff1a; 固定间隔时间重试&#xff1a;实现简单、但是可能导致重试过于频繁或稀疏&#xff0c;从而影响系统性能。如果重试间隔太短&#xff0c;可能导致雪崩效应&#xff1b;如果太长&#xff0c;可能影响用户体…

最小生成树算法

文章目录 最小生成树概述 P r i m Prim Prim 算法 - 稠密图 - O ( n 2 ) O(n^2) O(n2)思路概述时间复杂度分析AcWing 858. Prim算法求最小生成树CODE K r u s k a l Kruskal Kruskal 算法 - 稀疏图 - O ( m l o g m ) O(mlogm) O(mlogm)思路解析时间复杂度分析AcWing 859. Kr…

numpy二维数组新增第一列值并删除最后一列

numpy二维数组新增第一列值并删除最后一列 一、操作流程 1、先把第一列值取出来 2、使用random随机更新这一列的内容 3、使用切片删除最后一列 4、在数组第一列新增一列 二、示例代码 import randomimport numpy as npdata = np.array([[1, 1, 1, 1, 1,

管理类联考-性质

性质 ——性质—— 一、是什么 &#xff08;1&#xff09;本质&#xff1a;判断一定范围内的对象是否具备某个性质的命题就是性质命题&#xff08;直言命题&#xff09;。直言命题是断定事物/对象是否具有某种性质的命题。直言命题在结构上由主项、谓项、联项和量项组成。 &am…