示例#1
0
    private void Follow()
    {
        var followUnitsEntities = followUnits.Entities
                                  .Where(u => u.IsNotNullAndAlive());

        foreach (var unit in followUnitsEntities)
        {
            var followingComponent = unit.Get <FollowingComponent>();

            if (followingComponent?.TargetMovementComponent == null ||
                !followingComponent.TargetMovementComponent.IsObjectAlive)
            {
                FollowHelper.StopFollow(unit);
                MoveHelper.Stop(unit);
            }
            else
            {
                unit.Set <MovingComponent>().Destination = followingComponent.TargetMovementComponent.CurrentPosition;
            }
        }
    }
    private void StartMove()
    {
        var startMovingUnitsEntities = startMovingUnits.Entities
                                       .Take(startMovingUnits.GetEntitiesCount());

        foreach (var unit in startMovingUnitsEntities)
        {
            if (unit.Get <FollowingComponent>() != null)
            {
                FollowHelper.StopFollow(unit);
            }
            if (unit.Get <MovementComponent>() != null)
            {
                MoveHelper.Stop(unit);
            }

            var destinationPosition = unit.Get <StartMovingEvent>().Destination;

            unit.Set <MovingComponent>().Destination = destinationPosition;
            unit.Unset <StartMovingEvent>();
        }
    }