Initial Commit
This commit is contained in:
commit
ee5c2f922d
2255 changed files with 547750 additions and 0 deletions
40
Assets/Scripts/Systems/Actor/ActorGroundCheckSystem.cs
Normal file
40
Assets/Scripts/Systems/Actor/ActorGroundCheckSystem.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||
public class ActorGroundCheckSystem : InjectableComponentSystem
|
||||
{
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
public float GroundCheckDistance;
|
||||
public LayerMask GroundMask;
|
||||
public float MaxGroundCheckDistance;
|
||||
}
|
||||
|
||||
[Inject] private readonly Settings settings;
|
||||
private readonly RaycastHit2D[] hits = new RaycastHit2D[1];
|
||||
|
||||
protected override void OnSystemUpdate()
|
||||
{
|
||||
Entities.ForEach(
|
||||
(Rigidbody2D rigidBody, ref ActorData actor) =>
|
||||
{
|
||||
var filter = new ContactFilter2D { useLayerMask = true, layerMask = settings.GroundMask };
|
||||
var hitCount = rigidBody.Cast(Vector2.down, filter, hits, settings.MaxGroundCheckDistance);
|
||||
actor.Grounded = hitCount > 0 && hits.Any(h => h.distance <= settings.GroundCheckDistance);
|
||||
actor.GroundUp = hitCount > 0 ? hits[0].normal : Vector2.up;
|
||||
actor.GroundDinstance = hitCount > 0 ? hits.Min(h => h.distance) : -1;
|
||||
if (hitCount > 0)
|
||||
{
|
||||
Debug.DrawLine(hits[0].point, hits[0].point + hits[0].normal * hits[0].distance, Color.red);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue