36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
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++;
|
|
}
|
|
}
|
|
}
|
|
} |