Exemplo n.º 1
0
        /// <summary>
        /// Добавить маршрут в таблицу
        /// </summary>
        /// <param name="mapDelivery"></param>
        /// <returns></returns>
        public int CreateRoute(List <DeliveryPoint> mapDelivery)
        {
            DeliveryPoint LastPoint        = RoutesList.Last();
            int           idRoute          = LastPoint.Id + 1;
            int           priorityNewRoute = 2;

            //Поиск максимального приоритета, из всех где встречается клиент
            foreach (DeliveryPoint point in mapDelivery)
            {
                List <int> routes = (from p in RoutesList
                                     where p.IdCustomer == point.IdCustomer
                                     select p.PriorityRoute
                                     ).Distinct().ToList();
                int maxPriority = 0;
                if (routes.Count > 0)
                {
                    maxPriority = routes.Max();
                }

                priorityNewRoute = maxPriority > priorityNewRoute ? maxPriority + 1 : priorityNewRoute;
            }

            int priorityPoint = 0;

            foreach (DeliveryPoint point in mapDelivery)
            {
                RoutesTable.ListRows.Add();
                ListRow row = RoutesTable.ListRows[RoutesTable.ListRows.Count];
                row.Range[1, RoutesTable.ListColumns["Id route"].Index].Value             = idRoute;
                row.Range[1, RoutesTable.ListColumns["Priority route"].Index].Value       = priorityNewRoute;
                row.Range[1, RoutesTable.ListColumns["Priority point"].Index].Value       = ++priorityPoint;
                row.Range[1, RoutesTable.ListColumns["Получатель материала"].Index].Value = point.IdCustomer;
                row.Range[1, RoutesTable.ListColumns["City"].Index].Value = point.City;

                //поиск этого же Получателя в другой строке
                string        customerName = string.IsNullOrEmpty(point.Customer) ? "" : point.Customer;
                DeliveryPoint findPoint    = RoutesList.Find(x => x.IdCustomer == point.IdCustomer && x.Customer != "");
                if (!string.IsNullOrWhiteSpace(findPoint.Customer))
                {
                    row.Range[1, RoutesTable.ListColumns["Город"].Index].Value         = findPoint.CityLongName;
                    row.Range[1, RoutesTable.ListColumns["Маршрут"].Index].Value       = findPoint.Route;
                    row.Range[1, RoutesTable.ListColumns["Направление"].Index].Value   = findPoint.RouteName;
                    row.Range[1, RoutesTable.ListColumns["Номер клиента"].Index].Value = findPoint.CustomerNumber;
                    if (!string.IsNullOrWhiteSpace(customerName))
                    {
                        customerName = findPoint.Customer;
                    }
                }
                row.Range[1, RoutesTable.ListColumns["Клиент"].Index].Value = point.Customer;
                row.Range[1, RoutesTable.ListColumns["Add"].Index].Value    = "Auto";
            }
            RoutesList = null;
            return(idRoute);
        }
    // Start is called before the first frame update
    void Start()
    {
        //Find all possible routes from current spawn location
        List <RoutesList> possibleRoutes = null;

        switch (VehicleType)
        {
        case TrafficType.Car:
            possibleRoutes = FindObjectOfType <TrafficSpawner>().CarRoutes.Where(r => r.From == spawnLocation).ToList();
            break;

        case TrafficType.Train:
            possibleRoutes = FindObjectOfType <TrafficSpawner>().TrainRoutes.Where(r => r.From == spawnLocation).ToList();
            break;

        case TrafficType.Boat:
            possibleRoutes = FindObjectOfType <TrafficSpawner>().BoatRoutes.Where(r => r.From == spawnLocation).ToList();
            break;

        case TrafficType.Bicycle:
            possibleRoutes = FindObjectOfType <TrafficSpawner>().CyclistRoutes.Where(r => r.From == spawnLocation).ToList();
            hasAnimations  = true;
            animator       = GetComponent <Animator>();
            break;

        case TrafficType.Pedestrian:
            possibleRoutes = FindObjectOfType <TrafficSpawner>().PedestrianRoutes.Where(r => r.From == spawnLocation).ToList();
            hasAnimations  = true;
            animator       = GetComponent <Animator>();
            break;
        }

        //Select random route if there are valid routes
        if (possibleRoutes != null)
        {
            var index = UnityEngine.Random.Range(0, possibleRoutes.Count - 1);
            route = possibleRoutes[index];
        }
        else //No valid routes found
        {
            Debug.LogError($"ERROR: Failed to create route for vehicle type: {VehicleType.ToString()}");
            Destroy(this);
        }

        //Set first waypoint
        nextWaypoint = route.Route[waypointIndex];

        //Set correct rotation facing the target location
        Quaternion targetRotation = Quaternion.LookRotation(nextWaypoint.transform.position - transform.position, Vector3.up);

        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 1000);
    }
Exemplo n.º 3
0
        public async Task Route_FindRoute_OK()
        {
            var routes = new RoutesList();

            routes.AddRange(new[] {
                new Route
                {
                    Name = "Classique"
                },
                new Route()
                {
                    Name = "London"
                },
                new Route()
                {
                    Name = "Mountain"
                }
            });

            var route = routes.FindRoute("London Classique");

            route.Name.Should().Be.EqualTo("Classique");
        }