Initial Commit

This commit is contained in:
Simeon Radivoev 2022-02-12 12:53:50 +02:00
commit ee5c2f922d
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
2255 changed files with 547750 additions and 0 deletions

View file

@ -0,0 +1,51 @@
using AI;
using Unity.Entities;
using UnityEngine;
namespace DefaultNamespace
{
public class EnemyTargetFinderSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach(
(ref Enemy enemy, ref RigidBody2DData actorRigidBody, ref ActorTargetData target) =>
{
if (!EntityManager.Exists(target.Target))
{
var closestDist = float.MaxValue;
var actorPos = actorRigidBody.Position;
var finalTarget = Entity.Null;
Entities.ForEach(
(Entity playerEntity, ref RigidBody2DData rigidBody, ref PlayerData playerData) =>
{
var d = Vector2.SqrMagnitude(actorPos - rigidBody.Position);
if (d < closestDist)
{
closestDist = d;
finalTarget = playerEntity;
}
});
target.Target = finalTarget;
}
});
Entities.ForEach(
(GoapAgentData agent, ref ActorTargetData target) =>
{
if (agent.States != null)
{
var targetVal = (GoapKeys.HasTarget, true);
if (EntityManager.Exists(target.Target))
{
agent.States.Add(targetVal);
}
else
{
agent.States.Remove(targetVal);
}
}
});
}
}
}