37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
[GameSystemGroup(typeof(DefaultAgentsSystemGroup))]
|
|
public class UnlockCrittersSystem : GameSystem, IUpdatable
|
|
{
|
|
[InjectService]
|
|
private IEntityCache _entityCache;
|
|
|
|
[InjectService]
|
|
private IEntityCollection _entityCollection;
|
|
|
|
[InjectService]
|
|
private IIntentLogicExecutor _intentLogicExecutor;
|
|
|
|
public UnlockCrittersSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
foreach (var critter in _entityCache.GetCritterAgents())
|
|
{
|
|
ref var critterState = ref critter.GetCritterStateRW();
|
|
if (critterState.LockId == Entity.InvalidId || _entityCollection.Exists(critterState.LockId)) continue;
|
|
|
|
Debug.LogError($"Invalid lock id {critterState.LockId} on critter {critter.Id}");
|
|
|
|
critterState.LockId = Entity.InvalidId;
|
|
|
|
ref var intentQueue = ref _intentLogicExecutor.CancelRemainingIntents(critter);
|
|
IntentQueue.LoopWandering(ref intentQueue, 0);
|
|
}
|
|
}
|
|
}
|
|
} |