43 lines
1015 B
C#
43 lines
1015 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace Moonlit.FootstepPro
|
|
{
|
|
[AddComponentMenu("FootprintSystem/Detectors/MaximumDistanceToGround")]
|
|
public class MaximumDistanceToGround : IStepDetector
|
|
{
|
|
[SerializeField]
|
|
private float MaxDistance;
|
|
|
|
public override bool Detect(Foot foot)
|
|
{
|
|
List<RaycastHit> list = Physics.RaycastAll(foot.transform.position + foot.Controller.Up, -foot.Controller.Up).ToList();
|
|
if (list.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
List<RaycastHit> list2 = list.Where(delegate(RaycastHit x)
|
|
{
|
|
Surface component = x.collider.GetComponent<Surface>();
|
|
return component != null && component.Type != null;
|
|
}).ToList();
|
|
if (list2.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
RaycastHit[] array = list2.OrderBy((RaycastHit x) => x.distance).ToArray();
|
|
return array[0].distance - 1f < MaxDistance;
|
|
}
|
|
|
|
public override void Callback(bool footPlaced)
|
|
{
|
|
}
|
|
|
|
private void Reset()
|
|
{
|
|
_Type = CombineType.Required;
|
|
}
|
|
}
|
|
}
|