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 = ...
随机推荐
- python安装画图模块pillow
步骤一: install pillow (注意导入是 import PIL ) 步骤二:如果pycharm中import选择不到,则需要在settings中导入下 ...
- forms-隐藏处理
获取pin码. 查看网页源码<form action="" method="post"> PIN:<br> <inpu ...
- C#-----类DateTime的常用方法
1.TryParse(string s, out DateTime result) 将日期和时间的指定字符串表示形式转换为其 System.DateTime 等效项,并返回一个指示转换是否成功的 ...
- 0003.5-20180422-自动化第四章-python基础学习笔记--脚本
0003.5-20180422-自动化第四章-python基础学习笔记--脚本 1-shopping """ v = [ {"name": " ...
- AtomicReference
public class AtomicReference<V> implements java.io.Serializable { private static final long se ...
- 【.NET】 C# 时间戳和DataTime 互相转换
1.C# DateTime转换为Unix时间戳 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(, , )); // ...
- PAT (Basic Level) Practice (中文)1006 换个格式输出整数 (15 分)
题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805318855278592 #include <iost ...
- Github-记账本
- 第01节:ActiveMQ入门和消息中间件
1.ActiveMQ最主要的功能:实现JMS Provider,用来帮助实现高可用.高性能.可伸缩.易用和安全的企业级面向消息服务的系统.是一个异步的功能. 2.ActiveMQ特点: 完全支持JMS ...
- console.log在IE浏览器中会有异常
因为在IE浏览器无此方法,故此重写 方法一: var console = console || { log: function () { return false; } }; 方法二:window.c ...