You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.0 KiB
C#

3 weeks ago
using UnityEngine;
namespace Fusion.Addons.SimpleKCC
{
internal sealed class KCCShapeCastInfo
{
public Vector3 Position;
public float Radius;
public float Height;
public float Extent;
public Vector3 Direction;
public float MaxDistance;
public LayerMask LayerMask;
public QueryTriggerInteraction TriggerInteraction;
public KCCShapeCastHit[] AllHits;
public int AllHitCount;
public KCCShapeCastHit[] ColliderHits;
public int ColliderHitCount;
public KCCShapeCastHit[] TriggerHits;
public int TriggerHitCount;
public KCCShapeCastInfo()
: this(64)
{
}
public KCCShapeCastInfo(int maxHits)
{
AllHits = new KCCShapeCastHit[maxHits];
TriggerHits = new KCCShapeCastHit[maxHits];
ColliderHits = new KCCShapeCastHit[maxHits];
for (int i = 0; i < maxHits; i++)
{
AllHits[i] = new KCCShapeCastHit();
}
}
public void AddHit(RaycastHit raycastHit)
{
if (AllHitCount == AllHits.Length)
{
return;
}
KCCShapeCastHit kCCShapeCastHit = AllHits[AllHitCount];
if (kCCShapeCastHit.Set(raycastHit))
{
AllHitCount++;
if (kCCShapeCastHit.IsTrigger)
{
TriggerHits[TriggerHitCount] = kCCShapeCastHit;
TriggerHitCount++;
}
else
{
ColliderHits[ColliderHitCount] = kCCShapeCastHit;
ColliderHitCount++;
}
}
}
public void Reset(bool deep)
{
Position = default(Vector3);
Radius = 0f;
Height = 0f;
Extent = 0f;
Direction = default(Vector3);
MaxDistance = 0f;
Radius = 0f;
LayerMask = default(LayerMask);
TriggerInteraction = QueryTriggerInteraction.Collide;
AllHitCount = 0;
ColliderHitCount = 0;
TriggerHitCount = 0;
if (deep)
{
int i = 0;
for (int num = AllHits.Length; i < num; i++)
{
AllHits[i].Reset();
}
}
}
public void DumpHits(KCC kcc)
{
if (AllHitCount > 0)
{
kcc.Log($"ShapeCast Hits ({AllHitCount})");
_ = AllHits;
int i = 0;
for (int allHitCount = AllHitCount; i < allHitCount; i++)
{
KCCShapeCastHit kCCShapeCastHit = AllHits[i];
kcc.Log($"Collider: {kCCShapeCastHit.Collider.name}, Type: {kCCShapeCastHit.Type}, IsTrigger: {kCCShapeCastHit.IsTrigger}");
}
}
}
}
}