LineRenderer实现一个画线组件
using System;
using UnityEngine; class UILine
{
GameObject targetObj;
LineRenderer lineRenderer; //LineRenderer渲染出的线段的两个端点是3D世界中的点
int index = ;
int poinCount = ; //线段的端点数
Vector3 position; public void Start(GameObject go, Color beginColor, Color endColor, float begineWidth, float endWidth)
{
targetObj = go;
if (null != targetObj)
{
targetObj.SetActive(true);
lineRenderer = targetObj.GetComponent<LineRenderer>(); if (null == lineRenderer)
lineRenderer = targetObj.AddComponent<LineRenderer>();
} if (null != lineRenderer)
{
//颜色
lineRenderer.startColor = beginColor;
lineRenderer.endColor = endColor; //宽度
lineRenderer.startWidth = begineWidth;
lineRenderer.endWidth = endWidth;
} index = poinCount = ;
} public void Update()
{
if (Input.GetMouseButton())
{
//屏幕坐标转换为世界坐标
position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f));
//端点数+1
poinCount++;
//设置线段的端点数
lineRenderer.positionCount = poinCount; //连续绘制线段
while (index < poinCount)
{
//两点确定一条直线,所以我们依次绘制点就可以形成线段了
lineRenderer.SetPosition(index, position);
index++;
}
}
} public static UILine BeginLine(GameObject go, Color beginColor, Color endColor, float beginWidth, float endWidth)
{
UILine line = new UILine();
line.Start(go, beginColor, endColor, beginWidth, endWidth);
return line;
}
}
LineRenderer实现一个画线组件的更多相关文章
- unity3d NavMeshAgent 寻路画线/画路径
今天在群里看见有个小伙在问Game视图寻路时怎么画线 正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,自己也好学习一下 在百度查了一下资料,直接搜寻路画路径.寻路画线... ...
- Java 从零开始实现一个画图板、以及图像处理功能,代码可复现
Java 从零开始实现一个画图板.以及图像处理功能,代码可复现 这是一个学习分享博客,带你从零开始实现一个画图板.图像处理的小项目,为了降低阅读难度,本博客将画图板的一步步迭代优化过程展示给读者,篇幅 ...
- MFC画线功能总结
本文仅用于学习交流,商业用途请支持正版!转载请注明:http://www.cnblogs.com/mxbs/p/6216464.html MFC画线功能要点有二:其一,鼠标按下时记录初始位置为线的起始 ...
- MFC消息映射机制以及画线功能实现
---此仅供用于学习交流,切勿用于商业用途,转载请注明http://www.cnblogs.com/mxbs/p/6213404.html. 利用VS2010创建一个单文档标准MFC工程,工程名为Dr ...
- CGContextRef 画线简单用法
CGContextRef CGContextMoveToPoint(context,150,50);//圆弧的起始点 CGContextAddArcToPoint(context,100,80,130 ...
- Android中Path类的lineTo方法和quadTo方法画线的区别
转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...
- iOS小画板画线总结
一:基本画线: 使用贝赛尔曲线画: //创建路径 UIBezierPath* aPath = [UIBezierPath bezierPath]; //设置线宽 aPath.lineWidth = 5 ...
- [修复] Firemonkey 画线问题(Android & iOS 平台)
问题:官方 QC 的一个 Firemonkey 移动平台画线问题: RSP-14309: [iOS & Android] Delphi 10.1 Berlin - drawing proble ...
- WPF画线问题,几千条以后就有明显的延迟了。
我现在是这么画的,class A { private GeometryGroup _lines; private Path _path; public A() { _path.Data = ...
随机推荐
- PyAutoGUI使用
PyAutoGUI是一个纯Python的GUI自动化工具,其目的是可以用程序自动控制鼠标和键盘操作,利用它可以实现自动化任务,再也不用担心有重复枯燥的任务了. 安装: pip install pyau ...
- C语言实现迷宫小游戏
代码如下,时间太晚,有空补注释: #include<stdio.h> #include<string.h> #include<time.h> #include< ...
- ubuntu16.04下g++安装及使用
1)首先在虚拟机中安装Ubuntu16.04,网络模式设置为NAT模式,安装完成后在虚拟机中测试是否能够上网. 2)进入Ubuntu,按Ctrl+alt+T,调出终端,输入sudo su,输入密码切换 ...
- log4j2 标签解析
根节点Configuration有两个属性:status和monitorinterval,有两个子节点:Appenders和Loggers. status用来指定log4j本身的打印日志的级别. mo ...
- 日常开发自己遇到异常(BUG未完待续!!!)
在面试的时候经常会被问到你在项目中遇到的bug有哪些,或者你感觉你解决什么问题让你感觉有成就感.以此类似的面试问答,楼主现在开始不断更新日常遇到的BUG汇总 1:ConcurentModificati ...
- python的对象 变量
对象 所有的数据类型都是对象 字符串 数字:整数.数字 列表.字典 函数.类.模块.方法 print(type(20)) # 查看对象的数据类型 python整型: int 浮点型 :float 精 ...
- 并查集 P3367 【模板】并查集
P3367 [模板]并查集 #include<iostream> #include<algorithm> #include<cstdio> #include< ...
- bui前端框架+yii整理
这个是做bui前端样式整合的时候记录的. 首先当然是要下载一个yii的源码,搭建起来. 第一步将bui的样式迁移到yii的样式目录中去 这里我在样式外面加了一个bui的文件夹,表示这个文件夹中存放的是 ...
- 算法(第四版)C# 习题题解——2.5
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 查找更方便的版本见:https ...
- mongodb副本集基于centos7部署
安装mongodb,基于端口的安装三个节点 下载安装MongoDB安装包 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel ...