80 lines
1.7 KiB
C#
80 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace AutoPerformanceTests
|
|
{
|
|
public class AutoPerformanceTestSetup : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform[] _pointsToWalkAlong;
|
|
|
|
[SerializeField]
|
|
private bool _takeMemorySnapshots = true;
|
|
|
|
[SerializeField]
|
|
private bool _recordProfiler = true;
|
|
|
|
private Vector3[] _pointPositions;
|
|
|
|
[field: SerializeField]
|
|
public string TestName { get; private set; }
|
|
|
|
public bool TakeMemorySnapshots => _takeMemorySnapshots;
|
|
|
|
public bool RecordProfiler => _recordProfiler;
|
|
|
|
public int PointsCount => _pointPositions.Length;
|
|
|
|
public Vector3 GetPointPosition(int i)
|
|
{
|
|
return _pointPositions[i];
|
|
}
|
|
|
|
public Transform GetPointTransform(int i)
|
|
{
|
|
return _pointsToWalkAlong[i];
|
|
}
|
|
|
|
private void SnapPoints()
|
|
{
|
|
CorrectPointPositions();
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
GeneratePositionsArray();
|
|
}
|
|
|
|
private void CorrectPointPositions()
|
|
{
|
|
for (int i = 0; i < _pointsToWalkAlong.Length; i++)
|
|
{
|
|
Ray ray = new Ray(_pointsToWalkAlong[i].position, -Vector3.up);
|
|
RaycastHit hitInfo;
|
|
while (!Physics.Raycast(ray, out hitInfo))
|
|
{
|
|
_pointsToWalkAlong[i].position += new Vector3(0f, 1f, 0f);
|
|
ray = new Ray(_pointsToWalkAlong[i].position, -Vector3.up);
|
|
}
|
|
_pointsToWalkAlong[i].position += PositionYOffset(i, hitInfo);
|
|
}
|
|
}
|
|
|
|
private Vector3 PositionYOffset(int i, RaycastHit hit)
|
|
{
|
|
float num = 1.5f - hit.distance;
|
|
Vector3 zero = Vector3.zero;
|
|
zero.y += num;
|
|
return zero;
|
|
}
|
|
|
|
private void GeneratePositionsArray()
|
|
{
|
|
_pointPositions = new Vector3[_pointsToWalkAlong.Length];
|
|
for (int i = 0; i < _pointsToWalkAlong.Length; i++)
|
|
{
|
|
_pointPositions[i] = _pointsToWalkAlong[i].position;
|
|
}
|
|
}
|
|
}
|
|
}
|