forked from DeadlyApps/Unity-ECS-ZombieSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Unity.Collections; | ||
using Unity.Entities; | ||
using Unity.Mathematics; | ||
using Unity.Transforms; | ||
using Unity.Transforms2D; | ||
|
||
class HumanToZombieSystem : ComponentSystem | ||
{ | ||
struct HumansToConvertData | ||
{ | ||
public int Length; | ||
public ComponentDataArray<Human> Humans; | ||
[ReadOnly] public ComponentDataArray<Position2D> Positions; | ||
public EntityArray Entities; | ||
} | ||
|
||
[Inject] private HumansToConvertData humanData; | ||
|
||
protected override void OnUpdate() | ||
{ | ||
for (int i = 0; i < humanData.Length; i++) | ||
{ | ||
Human human = humanData.Humans[i]; | ||
if (human.IsInfected == 1) | ||
{ | ||
PostUpdateCommands.DestroyEntity(humanData.Entities[i]); | ||
|
||
PostUpdateCommands.CreateEntity(ZombieSimulatorBootstrap.ZombieArchetype); | ||
PostUpdateCommands.SetComponent(new Position2D { Value = humanData.Positions[i].Value }); | ||
PostUpdateCommands.SetComponent(new Heading2D { Value = new float2(1.0f, 0.0f) }); | ||
PostUpdateCommands.SetComponent(new MoveSpeed { speed = ZombieSettings.Instance.HumanSpeed }); | ||
|
||
// Finally we add a shared component which dictates the rendered look | ||
PostUpdateCommands.AddSharedComponent(ZombieSimulatorBootstrap.ZombieLook); | ||
|
||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters