37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using Random = UnityEngine.Random;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(DefaultAgentsSystemGroup))]
|
|
public class CritterHerdMoveCenterSystem : GameSystem, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private IEntityCollection _entityCollection;
|
|
|
|
[InjectService]
|
|
private World _world;
|
|
|
|
[InjectService]
|
|
private ISignalBus _signalBus;
|
|
|
|
public CritterHerdMoveCenterSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
foreach (CritterHerd herd in _entityCollection.GetInternalEntityList(typeof(CritterHerd)))
|
|
{
|
|
if (!_world.BlockMap.IsBlocked(herd.Center, BlockReason.BlocksAgents)) continue;
|
|
|
|
var oldCenter = herd.Center;
|
|
var moveDirection = ((Directions)Random.Range(0, 8)).ToVector();
|
|
var center = oldCenter + 4 * moveDirection;
|
|
|
|
if (!_world.Contains(center) || _world.BlockMap.IsBlocked(center, BlockReason.BlocksAgents)) continue;
|
|
|
|
herd.Center = center;
|
|
}
|
|
}
|
|
}
|
|
} |