protected override void OnUpdate() { // -- EatSystem_Eating InPlace inPlace = new InPlace { Place = Place.Home, }; Entities .WithName("EatSystem_Eating") .WithSharedComponentFilter(inPlace) .ForEach((Entity e, ref IsEating isEating) => { }) .ScheduleParallel(); }
protected override void OnUpdate() { // -- RelaxSystem_Main var mainCmdBuffer = _endSimulationCmdBuffer.CreateCommandBuffer().AsParallelWriter(); InPlace inPlace = new InPlace { Place = Place.Mine, }; GameTime gameTime = GetSingleton <GameTime>(); float deltaTime = gameTime.Delta; Entities .WithName("RelaxSystem_Main") .WithSharedComponentFilter(inPlace) .ForEach((Entity entity, int entityInQueryIndex, ref EnergyStat energyStat, in EnergyRegeneration energyRegeneration, in EnergyDestination energyDestination) => { energyStat.Count += energyRegeneration.Value * deltaTime; if (energyStat.Count >= energyDestination.Value) { mainCmdBuffer.RemoveComponent <EnergyDestination>(entityInQueryIndex, entity); } })
protected override void OnUpdate() { // Assign values to local variables captured in your job here, so that it has everything it // needs to do its work when it runs later. For example, float deltaTime = Time.DeltaTime; // This declares a new kind of job, which is a unit of work to do. The job is declared as an // Entities.ForEach with the target components as parameters, meaning it will process all // entities in the world that have both Translation and Rotation components. Change it to // process the component types you want. // -- WorkSystem_Main var mainCmdBuffer = _endSimulationCmdBuffer.CreateCommandBuffer().AsParallelWriter(); InPlace inPlace = new InPlace { Place = Place.Mine, }; GameTime gameTime = GetSingleton <GameTime>(); float deltaTime = gameTime.Delta; Entities .WithName("WorkSystem_Main") .WithSharedComponentFilter(inPlace) .WithNone <EnergyDestination>() .ForEach((Entity entity, int entityInQueryIndex, ref EnergyStat energyStat, in WorkStat workStat) => { energyStat.Count -= deltaTime * workStat.Speed * energyStat.FatiguePressure; if (energyStat.Count <= 10) { mainCmdBuffer.AddComponent <EnergyDestination>(entityInQueryIndex, entity, new EnergyDestination() { Value = 25 }); } }) .ScheduleParallel(); _endSimulationCmdBuffer.AddJobHandleForProducer(this.Dependency); }
protected override void OnUpdate() { var gameTime = GetSingleton <GameTime>(); var hour = gameTime.Hours; bool shouldAddDependencies = false; if (hour == 5) { _regeneratedEnergy = false; } else if (!_regeneratedEnergy && hour == 6) { EntityCommandBuffer entityCmdBuffer = new EntityCommandBuffer(Allocator.TempJob, PlaybackPolicy.SinglePlayback); var cmdBuffer = entityCmdBuffer.AsParallelWriter(); var handle = Entities .ForEach((Entity e, int entityInQueryIndex, ref EnergyStat energyStat) => { energyStat.Count = 100; cmdBuffer.RemoveComponent <IsSleeping>(entityInQueryIndex, e); }) .ScheduleParallel(Dependency); _regeneratedEnergy = true; handle.Complete(); entityCmdBuffer.Playback(EntityManager); entityCmdBuffer.Dispose(); Dependency = default; } if (hour >= 23 || hour < 6) { EntityManager.AddComponent(_sleepQuery, _isSleepType); } else if ((hour >= 6 && hour < 7) || (hour >= 20 && hour < 21)) { EntityManager.AddComponent(_eatQuery, _isEatingType); } else if (hour == 7) { var cmdBuffer = _beginSimulationCmdBuffer.CreateCommandBuffer().AsParallelWriter(); var isEatingType = _isEatingType; InPlace filter = new InPlace() { Place = Place.Home }; Entities .WithNone <Heading>() .WithAll <IsEating>() .WithSharedComponentFilter(filter) .WithoutBurst() .ForEach((Entity e, int entityInQueryIndex) => { cmdBuffer.AddComponent(entityInQueryIndex, e, new Heading() { Place = Place.Mine }); cmdBuffer.SetSharedComponent(entityInQueryIndex, e, new InPlace() { Place = Place.InTravel }); cmdBuffer.RemoveComponent(entityInQueryIndex, e, isEatingType); }) .ScheduleParallel(); shouldAddDependencies = true; } else if (hour == 18) { var mainCmdBuffer = _beginSimulationCmdBuffer.CreateCommandBuffer().AsParallelWriter(); InPlace filter = new InPlace() { Place = Place.Mine }; EntityManager.RemoveComponent(_removeEnergyDestination, _energyDestinationType); Entities .WithNone <Heading>() .WithSharedComponentFilter(filter) .WithoutBurst() .ForEach((Entity e, int entityInQueryIndex) => { mainCmdBuffer.AddComponent(entityInQueryIndex, e, new Heading() { Place = Place.Home }); mainCmdBuffer.SetSharedComponent(entityInQueryIndex, e, new InPlace() { Place = Place.InTravel }); }) .ScheduleParallel(); shouldAddDependencies = true; } else if (hour == 21) { var cmdBuffer = _beginSimulationCmdBuffer.CreateCommandBuffer().AsParallelWriter(); var isEatingType = _isEatingType; Entities .WithAll <IsEating>() .ForEach((Entity e, int entityInQueryIndex) => { cmdBuffer.RemoveComponent(entityInQueryIndex, e, isEatingType); }) .ScheduleParallel(); shouldAddDependencies = true; } if (shouldAddDependencies) { _beginSimulationCmdBuffer.AddJobHandleForProducer(Dependency); } }