1. using System;
  2. using UnityEngine;
  3.  
  4. class UILine
  5. {
  6. GameObject targetObj;
  7. LineRenderer lineRenderer; //LineRenderer渲染出的线段的两个端点是3D世界中的点
  8. int index = ;
  9. int poinCount = ; //线段的端点数
  10. Vector3 position;
  11.  
  12. public void Start(GameObject go, Color beginColor, Color endColor, float begineWidth, float endWidth)
  13. {
  14. targetObj = go;
  15. if (null != targetObj)
  16. {
  17. targetObj.SetActive(true);
  18. lineRenderer = targetObj.GetComponent<LineRenderer>();
  19.  
  20. if (null == lineRenderer)
  21. lineRenderer = targetObj.AddComponent<LineRenderer>();
  22. }
  23.  
  24. if (null != lineRenderer)
  25. {
  26. //颜色
  27. lineRenderer.startColor = beginColor;
  28. lineRenderer.endColor = endColor;
  29.  
  30. //宽度
  31. lineRenderer.startWidth = begineWidth;
  32. lineRenderer.endWidth = endWidth;
  33. }
  34.  
  35. index = poinCount = ;
  36. }
  37.  
  38. public void Update()
  39. {
  40. if (Input.GetMouseButton())
  41. {
  42. //屏幕坐标转换为世界坐标
  43. position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f));
  44. //端点数+1
  45. poinCount++;
  46. //设置线段的端点数
  47. lineRenderer.positionCount = poinCount;
  48.  
  49. //连续绘制线段
  50. while (index < poinCount)
  51. {
  52. //两点确定一条直线,所以我们依次绘制点就可以形成线段了
  53. lineRenderer.SetPosition(index, position);
  54. index++;
  55. }
  56. }
  57. }
  58.  
  59. public static UILine BeginLine(GameObject go, Color beginColor, Color endColor, float beginWidth, float endWidth)
  60. {
  61. UILine line = new UILine();
  62. line.Start(go, beginColor, endColor, beginWidth, endWidth);
  63. return line;
  64. }
  65. }

LineRenderer实现一个画线组件的更多相关文章

  1. unity3d NavMeshAgent 寻路画线/画路径

    今天在群里看见有个小伙在问Game视图寻路时怎么画线 正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,自己也好学习一下 在百度查了一下资料,直接搜寻路画路径.寻路画线... ...

  2. Java 从零开始实现一个画图板、以及图像处理功能,代码可复现

    Java 从零开始实现一个画图板.以及图像处理功能,代码可复现 这是一个学习分享博客,带你从零开始实现一个画图板.图像处理的小项目,为了降低阅读难度,本博客将画图板的一步步迭代优化过程展示给读者,篇幅 ...

  3. MFC画线功能总结

    本文仅用于学习交流,商业用途请支持正版!转载请注明:http://www.cnblogs.com/mxbs/p/6216464.html MFC画线功能要点有二:其一,鼠标按下时记录初始位置为线的起始 ...

  4. MFC消息映射机制以及画线功能实现

    ---此仅供用于学习交流,切勿用于商业用途,转载请注明http://www.cnblogs.com/mxbs/p/6213404.html. 利用VS2010创建一个单文档标准MFC工程,工程名为Dr ...

  5. CGContextRef 画线简单用法

    CGContextRef CGContextMoveToPoint(context,150,50);//圆弧的起始点 CGContextAddArcToPoint(context,100,80,130 ...

  6. Android中Path类的lineTo方法和quadTo方法画线的区别

    转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...

  7. iOS小画板画线总结

    一:基本画线: 使用贝赛尔曲线画: //创建路径 UIBezierPath* aPath = [UIBezierPath bezierPath]; //设置线宽 aPath.lineWidth = 5 ...

  8. [修复] Firemonkey 画线问题(Android & iOS 平台)

    问题:官方 QC 的一个 Firemonkey 移动平台画线问题: RSP-14309: [iOS & Android] Delphi 10.1 Berlin - drawing proble ...

  9. WPF画线问题,几千条以后就有明显的延迟了。

      我现在是这么画的,class A { private GeometryGroup _lines; private Path _path; public A() {    _path.Data = ...

随机推荐

  1. python安装画图模块pillow

    步骤一: install pillow (注意导入是 import PIL )       步骤二:如果pycharm中import选择不到,则需要在settings中导入下             ...

  2. forms-隐藏处理

    获取pin码. 查看网页源码<form action="" method="post">    PIN:<br>    <inpu ...

  3. C#-----类DateTime的常用方法

    1.TryParse(string s, out DateTime result)    将日期和时间的指定字符串表示形式转换为其 System.DateTime 等效项,并返回一个指示转换是否成功的 ...

  4. 0003.5-20180422-自动化第四章-python基础学习笔记--脚本

    0003.5-20180422-自动化第四章-python基础学习笔记--脚本 1-shopping """ v = [ {"name": " ...

  5. AtomicReference

    public class AtomicReference<V> implements java.io.Serializable { private static final long se ...

  6. 【.NET】 C# 时间戳和DataTime 互相转换

    1.C# DateTime转换为Unix时间戳 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(, , )); // ...

  7. PAT (Basic Level) Practice (中文)1006 换个格式输出整数 (15 分)

    题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805318855278592 #include <iost ...

  8. Github-记账本

  9. 第01节:ActiveMQ入门和消息中间件

    1.ActiveMQ最主要的功能:实现JMS Provider,用来帮助实现高可用.高性能.可伸缩.易用和安全的企业级面向消息服务的系统.是一个异步的功能. 2.ActiveMQ特点: 完全支持JMS ...

  10. console.log在IE浏览器中会有异常

    因为在IE浏览器无此方法,故此重写 方法一: var console = console || { log: function () { return false; } }; 方法二:window.c ...