public virtual void Reset(IHealthSource healthSource, Transform spawnPoint) {
        HealthStatsInfo healthStatsInfo = new HealthStatsInfo(healthSource, unit.Health.Max, unit.Health.Max);
        unit.Health.SetStats(healthStatsInfo);

        movement.Reset(spawnPoint);

        foreach(Ability ability in unit.Abilities) {
            ability.Reset();
        }

        enabled = true;
        StopAll();

        unit.Ragdoll.Hide();

        unit.gameObject.SetActive(true);
    }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <UnitMovement> movements = chunk.GetNativeArray(UnitMovementType);

            NativeArray <MoveTo> unitMoveTo = chunk.GetNativeArray(UnitMoveToType);

            NativeArray <Entity> entities = chunk.GetNativeArray(EntityType);

            for (var i = 0; i < movements.Length; i++)
            {
                var move   = movements[i];
                var moveTo = unitMoveTo[i];

                if (move.CurrentCellCoord.x != moveTo.Coord.x || move.CurrentCellCoord.y != moveTo.Coord.y)
                {
                    EntityCommandBuffer.AddComponent <Path>(chunkIndex, entities[i]);

                    EntityCommandBuffer.SetComponent(chunkIndex, entities[i], new Path
                    {
                        StartCoord = move.CurrentCellCoord,
                        GoalCoord  = moveTo.Coord,
                        InProgress = true,
                        Reachable  = false
                    });

                    EntityCommandBuffer.AddBuffer <PathNode>(chunkIndex, entities[i]);
                    EntityCommandBuffer.AddBuffer <SearchNode>(chunkIndex, entities[i]);

                    movements[i] = UnitMovement.Reset(move);

#if UNITY_EDITOR
                    EntityCommandBuffer.AddBuffer <DebugNode>(chunkIndex, entities[i]);
#endif
                }

                EntityCommandBuffer.RemoveComponent <MoveTo>(chunkIndex, entities[i]);
            }
        }
    protected override void OnUpdate()
    {
        var units    = _entityQuery.ToComponentDataArray <Unit>(Allocator.TempJob);
        var pathes   = _entityQuery.ToComponentDataArray <Path>(Allocator.TempJob);
        var entities = _entityQuery.ToEntityArray(Allocator.TempJob);
        var movement = _entityQuery.ToComponentDataArray <UnitMovement>(Allocator.TempJob);

        _pathBuffer = GetBufferFromEntity <PathNode>(true);

        float dt = Time.DeltaTime;

        for (int i = 0; i < entities.Length; i++)
        {
            var path = pathes[i];
            var move = movement[i];

            if (!path.InProgress)
            {
                if (path.Reachable)
                {
                    if (move.IsMoving)
                    {
                        move.StepProgress += dt * move.Speed;

                        if (move.StepProgress >= 1f)
                        {
                            SwitchMapData(move, units[i], entities[i], move.TargetCellCoord);
                            move.StepProgress     = 1f;
                            move.IsMoving         = false;
                            move.CurrentCellCoord = move.TargetCellCoord;
                        }
                    }
                    else
                    {
                        DynamicBuffer <PathNode> pathNodeBuffer = _pathBuffer[entities[i]];

                        int pathPosIndex = math.max(pathNodeBuffer.Length - 1 - move.PathPositionIndex, 0);

                        PathNode pathPos = pathNodeBuffer[pathPosIndex];

                        if (move.CurrentCellCoord.x != pathPos.Coord.x || move.CurrentCellCoord.y != pathPos.Coord.y)
                        {
                            var mapData = _mapDataSystem.MapData[pathPos.Coord];

                            if (mapData.ContentEntity != Entity.Null)
                            {
                                move.WaitTimer += dt;

                                if (move.WaitTimer > 1f)
                                {
                                    PostUpdateCommands.RemoveComponent <Path>(entities[i]);
                                }

                                movement[i] = move;
                                continue;
                            }

                            move.WaitTimer               = 0;
                            move.IsMoving                = true;
                            move.StepProgress            = 0f;
                            move.TargetCellCoord         = pathPos.Coord;
                            move.TargetTransformPosition = _grid.CellToWorld(new Vector3Int(move.TargetCellCoord.x, move.TargetCellCoord.y, 0));
                            move.PathPositionIndex      += 1;
                        }
                        else
                        {
                            if (move.PathPositionIndex < pathNodeBuffer.Length - 1)
                            {
                                move.PathPositionIndex += 1;
                            }
                            else
                            {
                                PostUpdateCommands.RemoveComponent <Path>(entities[i]);
                            }
                        }
                    }
                }
                else
                {
                    PostUpdateCommands.RemoveComponent <Path>(entities[i]);
                }
            }
            else
            {
                move = UnitMovement.Reset(move);
            }

            movement[i] = move;
        }

        _entityQuery.CopyFromComponentDataArray(movement);

        pathes.Dispose();
        entities.Dispose();
        units.Dispose();
        movement.Dispose();
    }