1
This commit is contained in:
36
Unity/Scripts/Renderer/LineConnector.cs
Normal file
36
Unity/Scripts/Renderer/LineConnector.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
namespace BITKit
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class LineConnector : MonoBehaviour
|
||||
{
|
||||
public LineRenderer lineRenderer;
|
||||
public Transform[] points;
|
||||
public float radius = 0.64f;
|
||||
public int excuteTimes;
|
||||
void Update()
|
||||
{
|
||||
if (lineRenderer && points.Length > 0)
|
||||
{
|
||||
var list = ListPool<Vector3>.Get();
|
||||
var currentPosition = points[0].position;
|
||||
list.Add(currentPosition);
|
||||
foreach (var point in points)
|
||||
{
|
||||
if (Vector3.Distance(point.position, currentPosition) >= radius)
|
||||
{
|
||||
list.Add(currentPosition = point.position);
|
||||
}
|
||||
//list.Add(point.position);
|
||||
}
|
||||
lineRenderer.positionCount =list.Count;
|
||||
lineRenderer.SetPositions(list.ToArray());
|
||||
ListPool<Vector3>.Release(list);
|
||||
excuteTimes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user