r2mods/ilspy_dump/ror2_csproj/LineBetweenTransforms.cs

66 lines
1.3 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System;
using UnityEngine;
using UnityEngine.Serialization;
[RequireComponent(typeof(LineRenderer))]
[ExecuteAlways]
public class LineBetweenTransforms : MonoBehaviour
{
[SerializeField]
[FormerlySerializedAs("transformNodes")]
[Tooltip("The list of transforms whose positions will drive the vertex positions of the sibling LineRenderer component.")]
private Transform[] _transformNodes = Array.Empty<Transform>();
private LineRenderer lineRenderer;
private Vector3[] vertexList = Array.Empty<Vector3>();
public Transform[] transformNodes
{
get
{
return _transformNodes;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_transformNodes = value;
UpdateVertexBufferSize();
}
}
private void PushPositionsToLineRenderer()
{
Vector3[] array = vertexList;
Transform[] array2 = transformNodes;
for (int i = 0; i < array.Length; i++)
{
Transform transform = array2[i];
if ((bool)transform)
{
array[i] = transform.position;
}
}
lineRenderer.SetPositions(array);
}
private void UpdateVertexBufferSize()
{
Array.Resize(ref vertexList, transformNodes.Length);
}
private void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
UpdateVertexBufferSize();
}
private void LateUpdate()
{
PushPositionsToLineRenderer();
}
}