Example #1
0
        private RoadBehaviour InstantiateRoadAtPosition(RoadBehaviour newRoad)
        {
            var road = Instantiate(newRoad, _lastRoad.Edge);

            road.transform.localPosition = Vector3.zero;
            road.transform.localRotation = Quaternion.EulerAngles(Vector3.zero);

            road.transform.SetParent(_parent, true);

            _forward = road.Edge.forward;

            return(road);
        }
    public override void Initialize()
    {
        ZoneID = ++ZoneIDUnique;

        if (ZoneID == -1) Debug.LogError("ZoneID not set! Check!");
        else {
            Vector3 intersection_distance_vector = (transform.position - Intersection.transform.position);
            intersection_distance = intersection_distance_vector.x;
            if (intersection_distance_vector.y > intersection_distance) intersection_distance = intersection_distance_vector.y;
            if(intersection_distance_vector.z > intersection_distance) intersection_distance = intersection_distance_vector.z;
            intersection_length = Intersection.transform.localScale.z;
            lane_hot_id = RoadBehaviour.GetLaneID(Lane);
            VehicleCountHisto.Add(ZoneID, 0);
            CruiseValueHisto.Add(ZoneID, -1f);
        }
    }
Example #3
0
        public void Generate(Transform parent, int roadCount = 10)
        {
            _parent = parent;
            for (int i = 0; i < roadCount; i++)
            {
                if (i == 0)
                {
                    _lastRoad = Instantiate(RoadDictionary.GetRandomRegular(), parent);
                    continue;
                }

                if (i == roadCount - 1)
                {
                    _lastRoad = InstantiateRoadAtPosition(RoadDictionary.Finish);
                    _forward  = _lastRoad.Edge.forward;
                    continue;
                }

                if (_lastRoad.RoadType == RoadType.RightTurn)
                {
                    if (_forward == Vector3.right)
                    {
                        _lastRoad = InstantiateRoadAtPosition(RoadDictionary.GetRandomLeft());
                        continue;
                    }
                    else if (_forward == Vector3.forward)
                    {
                        _lastRoad = InstantiateRoadAtPosition(RoadDictionary.LeftTurn);
                        continue;
                    }
                }

                if (_lastRoad.RoadType == RoadType.LeftTurn)
                {
                    if (_forward == Vector3.left)
                    {
                        _lastRoad = InstantiateRoadAtPosition(RoadDictionary.GetRandomRight());
                        continue;
                    }
                    else if (_forward == Vector3.forward)
                    {
                        _lastRoad = InstantiateRoadAtPosition(RoadDictionary.RightTurn);
                        continue;
                    }
                }

                if (_lastRoad.RoadType == RoadType.U_RightTurn)
                {
                    if (_forward == Vector3.right)
                    {
                        _lastRoad = InstantiateRoadAtPosition(RoadDictionary.GetRandomLeft());
                        continue;
                    }
                }

                if (_lastRoad.RoadType == RoadType.U_LeftTurn)
                {
                    if (_forward == Vector3.left)
                    {
                        _lastRoad = InstantiateRoadAtPosition(RoadDictionary.GetRandomRight());
                        continue;
                    }
                }
            }
        }