riversong code showcase
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class CritterHerdsGeneratorOperation : IWorldGeneratorOperation
|
||||
{
|
||||
[InjectService]
|
||||
private IEntityCollection _entityCollection;
|
||||
|
||||
[InjectService]
|
||||
private IGameDatabase _gameDatabase;
|
||||
|
||||
[InjectService]
|
||||
private IAgentFactory _agentFactory;
|
||||
|
||||
public UniTask Execute(World world)
|
||||
{
|
||||
var critters = _gameDatabase.OfType<CritterDefinition>();
|
||||
|
||||
foreach (var eligibleCenter in world.CritterHerdsState.EligibleCenters)
|
||||
{
|
||||
var critter = critters[Random.Range(0, critters.Count)];
|
||||
|
||||
var herd = _entityCollection.CreateAndAdd<CritterHerd>();
|
||||
herd.CritterDefinition = critter;
|
||||
herd.Center = eligibleCenter;
|
||||
herd.MaxCritterCount = Random.Range(critter.MinCritterCount, critter.MaxCritterCount + 1);
|
||||
|
||||
_agentFactory.InitializeAgentSource(herd);
|
||||
}
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user