Esempio n. 1
0
        public Route(Road fromEnd, Road toEnd, bool is_temp = false)
        {
            if (fromEnd == null || toEnd == null)
            {
                throw new ArgumentNullException("from/to");
            }

            if (fromEnd.type != RoadType.End || toEnd.type != RoadType.End)
            {
                throw new ArgumentException("from's and/or to's type is not RoadType.End");
            }

            _Init(RouteCreator.CreatePathWP(fromEnd, toEnd, true), is_temp);
        }
Esempio n. 2
0
        public static IEnumerator CheckRoutes()
        {
            while (checking)
            {
                if (routes.Count > 0)
                {
                    Timer timer = new Timer();
                    timer.Start();

                    for (int i = 0; i < routes.Count; i++)
                    {
                        Route route = routes[i];

                        int curr = 0, last = route.Count - 1;

                        while (curr != last)
                        {
                            if (route[curr] == null)
                            {
                                Timer t = new Timer();
                                t.Start();

                                route.UpdateTempStartWP();

                                var newRoute = RouteCreator.CreatePathWP(route.startWP, route.endWP, !route.IsTemp);

                                route.Set(newRoute);

                                Debug.Log("<color=orange>Coroutine route " + route.RouteID + " recalculation:</color><color=green> " + t.ElapsedTime(Timer.Units.Milliseconds) + " ms.</color>");

                                break;
                                //yield return null;
                            }
                            else
                            {
                                curr++;
                            }
                        }
                    }

                    Debug.Log("Coroutine routes recalculation:<color=green> " + timer.ElapsedTime(Timer.Units.Milliseconds) + " ms.</color>");
                }

                HighLightAll(false);
                GizmosDrawer.Clear();
                HighLightAll(true);

                yield return(new WaitUntil(() => { return Time.frameCount % 10 == 0; }));
            }
        }
Esempio n. 3
0
        public static void RecalculateRoutes(Road changed = null)
        {
            if (Count < 1)
            {
                return;
            }

            if (changed == null)
            {
                for (int i = 0; i < Count; i++)
                {
                    Route routesI = routes[i];
                    routesI.HighLight(false);

                    Debug.Log("Recalculation: Route " + routesI.RouteID + ", temp - " + routesI.IsTemp);

                    var newRoute = RouteCreator.CreatePathWP(routesI.startWP, routesI.endWP, !routesI.IsTemp);
                    routesI.Set(newRoute);

                    routesI.HighLight(true, routesI.IsTemp ? Color.red : Color.green);
                }
                return;
            }
            else
            {
                for (int i = 0; i < Count; i++)
                {
                    Route routesI = routes[i];

                    if (routesI.Contains(changed))
                    {
                        Debug.Log("Recalculation: " + changed.ToString());

                        if (routesI[0] == changed || routesI[routesI.Count / 2] == changed)
                        {
                            Debug.Log("<color=red>Route " + routesI.RouteID + ": Begin or End was deleted!</color>");
                            routesI.Set(null); // ToImplement
                        }
                        else
                        {
                            var newRoute = RouteCreator.CreatePathWP(routesI.startWP, routesI.endWP, !routesI.IsTemp);

                            if (newRoute == null)
                            {
                            }


                            if (newRoute == null)
                            {
                                Debug.Log("<color=red>Route " + routesI.RouteID + ": Path does not exist anymore!</color>");
                            }
                            else
                            {
                                Debug.Log("<color=green>Route " + routesI.RouteID + ": Path recalculated successfully.</color>");
                            }

                            routesI.HighLight(false);
                            routesI.Set(newRoute);
                            routesI.HighLight(true, routesI.IsTemp ? Color.red : Color.green);
                        }
                    }
                }
            }
        }