Unity绘制参考网格

news/2024/11/8 15:05:25/

1.仿制Maya参考网格 

using UnityEngine;public class ReferenceGridRenderer : MonoBehaviour
{//[SerializeField] Color color = new Color(1, 1, 1, 0.5f);[SerializeField] [Range(1, 1000)] float range = 20;[SerializeField] [Range(0.1f, 100)] float interval = 1;[SerializeField] float centerLineWidth = 0.05f;[SerializeField] float outerLineWidth = 0.01f;[SerializeField] Color centerLineColor = Color.white;[SerializeField] Color outerLineColor = new Color(1, 1, 1, 0.5f);void Start(){CreateReferenceGrid();}void CreateReferenceGrid(){GameObject referenceGrid = new GameObject("Reference Grid");for (float i = -range; i <= range; i += interval){GameObject lineObjectX = new GameObject("Line X");lineObjectX.transform.SetParent(referenceGrid.transform);LineRenderer lineRendererX = lineObjectX.AddComponent<LineRenderer>();lineRendererX.material = new Material(Shader.Find("Sprites/Default"));lineRendererX.startColor = (i == 0) ? centerLineColor : outerLineColor;lineRendererX.endColor = (i == 0) ? centerLineColor : outerLineColor;lineRendererX.startWidth = (i == 0) ? centerLineWidth : outerLineWidth;lineRendererX.endWidth = (i == 0) ? centerLineWidth : outerLineWidth;GameObject lineObjectZ = new GameObject("Line Z");lineObjectZ.transform.SetParent(referenceGrid.transform);LineRenderer lineRendererZ = lineObjectZ.AddComponent<LineRenderer>();lineRendererZ.material = new Material(Shader.Find("Sprites/Default"));lineRendererZ.startColor = (i == 0) ? centerLineColor : outerLineColor;lineRendererZ.endColor = (i == 0) ? centerLineColor : outerLineColor;lineRendererZ.startWidth = (i == 0) ? centerLineWidth : outerLineWidth;lineRendererZ.endWidth = (i == 0) ? centerLineWidth : outerLineWidth;lineRendererX.SetPositions(new Vector3[] { new Vector3(-range, 0, i), new Vector3(range, 0, i) });lineRendererZ.SetPositions(new Vector3[] { new Vector3(i, 0, -range), new Vector3(i, 0, range) });}}
}

2.仿制 ThreeEditor 参考网格

using UnityEngine;public class ReferenceGridRenderer : MonoBehaviour
{[SerializeField] [Range(1, 1000)] float range = 20;[SerializeField] [Range(0.1f, 100)] float interval = 1;[SerializeField] float centerLineWidth = 0.05f;[SerializeField] float outerLineWidth = 0.01f;[SerializeField] Color centerLineColor = Color.white;[SerializeField] Color outerLineColor = new Color(1, 1, 1, 0.5f);[SerializeField] float fifthLineWidth = 0.02f;[SerializeField] Color fifthLineColor = new Color(1, 0, 0, 0.5f);void Start(){CreateReferenceGrid();}void CreateReferenceGrid(){GameObject referenceGrid = new GameObject("Reference Grid");int count = 0;for (float i = -range; i <= range; i += interval){GameObject lineObjectX = new GameObject("Line X");lineObjectX.transform.SetParent(referenceGrid.transform);LineRenderer lineRendererX = lineObjectX.AddComponent<LineRenderer>();lineRendererX.material = new Material(Shader.Find("Sprites/Default"));if (i == 0){lineRendererX.startColor = centerLineColor;lineRendererX.endColor = centerLineColor;lineRendererX.startWidth = centerLineWidth;lineRendererX.endWidth = centerLineWidth;}else if (count % 5 == 0){lineRendererX.startColor = fifthLineColor;lineRendererX.endColor = fifthLineColor;lineRendererX.startWidth = fifthLineWidth;lineRendererX.endWidth = fifthLineWidth;}else{lineRendererX.startColor = outerLineColor;lineRendererX.endColor = outerLineColor;lineRendererX.startWidth = outerLineWidth;lineRendererX.endWidth = outerLineWidth;}GameObject lineObjectZ = new GameObject("Line Z");lineObjectZ.transform.SetParent(referenceGrid.transform);LineRenderer lineRendererZ = lineObjectZ.AddComponent<LineRenderer>();lineRendererZ.material = new Material(Shader.Find("Sprites/Default"));if (i == 0){lineRendererZ.startColor = centerLineColor;lineRendererZ.endColor = centerLineColor;lineRendererZ.startWidth = centerLineWidth;lineRendererZ.endWidth = centerLineWidth;}else if (count % 5 == 0){lineRendererZ.startColor = fifthLineColor;lineRendererZ.endColor = fifthLineColor;lineRendererZ.startWidth = fifthLineWidth;lineRendererZ.endWidth = fifthLineWidth;}else{lineRendererZ.startColor = outerLineColor;lineRendererZ.endColor = outerLineColor;lineRendererZ.startWidth = outerLineWidth;lineRendererZ.endWidth = outerLineWidth;}lineRendererX.SetPositions(new Vector3[] { new Vector3(-range, 0, i), new Vector3(range, 0, i) });lineRendererZ.SetPositions(new Vector3[] { new Vector3(i, 0, -range), new Vector3(i, 0, range) });count++;}}
}


http://www.ppmy.cn/news/350525.html

相关文章

解决RHEL8.5下dotnetcore无法处理gif和jpg问题

之前是解决的8.5下的dotnet无法调libgdiplus绘图问题。解决之后发现只能处理bmp格式图。后面发现还能处理png格式图。对应gif和jpg格式的图则报错&#xff0c;为此专门写了测试程序测试这个问题。新电脑跑虚拟机真香&#xff0c;哈哈。 测试程序如下&#xff0c;如果加载gif和…

centos 计算器_在Linux命令行中使用计算器的5个命令

大家好&#xff0c;我是良许。 在使用 Linux 时&#xff0c;我们有时会需要做一些计算&#xff0c;那么我们就可能需要用到计算器。在 Linux 命令行里&#xff0c;有许多计算器工具&#xff0c;这些命令行计算器可以让我们执行科学计算、财务计算或者一些简单的计算。当然&…

termux使用无图形界面linux,在termux上使用图形化

最近老是被人问怎么在termux上用图形化(GUI),想来不如写一篇文章得了。 被人吐槽写的太抽象了,我改还不行吗 VNC Termux原生 准确来说,原生是不可能的,你不可能在termux那个窗口里用GUI的,你需要准备VNC Viewer或者XServer XSDL,这里以VNC Viewer为例。(据称VNC这个太麻烦…

【算法】跑ORB-SLAM2遇到的问题、解决方法、效果展示(环境:Ubuntu18.04+ROS melodic)

文章目录 一、Pangolin库的介绍和安装问题1、问题&#xff1a;Error: No preferred package managers from list [brew] found. Use -m to select manually.2、问题&#xff1a;"make: *** No rule to make target pypangolin_pip_install. Stop." 二、编译 ORB_SLAM…

Mybatis源码学习之全局配置文件和映射文件解析

全局配置文件和映射文件解析 全局配置文件解析 public static void main(String[] args) throws IOException {// 读取配置文件InputStream is Resources.getResourceAsStream("org/apache/ibatis/builder/MapperConfig1.xml");// 创建SqlSessionFactory工厂SqlSes…

python方向键控制角色_教你快速用 Python 控制键盘和鼠标,彻底解放双手

你还在为在计算机上双击或提交表单而烦恼吗?今天就用python来控制键盘和鼠标,解放双手! 第一,Pyauogui库 我们可以首先安装pyauogui库,通过它我们可以编写一些Python脚本来控制鼠标和键盘。例如,可以定义鼠标的点击位置、键盘的输入时间等,实现所有要操作的软件应用程序…

Linux中软件仓库的搭建与虚拟化的部署及应用

目录 一、软件仓库搭建 搭建epel仓库 dnf第三方软件仓库的搭建与共享 二、虚拟化的部署 下载并且安装 虚拟机快照的应用 总结 一、软件仓库搭建 搭建epel仓库 什么是epel EPEL 的全称叫 Extra Packages for Enterprise Linux。EPEL 是由 Fedora 社区打造&#xff0c;…

7 款可替代 top 命令的工具

作者&#xff1a;JackTian 来源&#xff1a;公众号「杰哥的IT之旅」 ID&#xff1a;Jake_Internet 转载请联系授权&#xff08;微信ID&#xff1a;Hc220088&#xff09; 原文地址&#xff1a;7 款可替代 top 命令的工具&#xff01;(二) 大家好&#xff0c;我是杰哥。 上一篇文…