Ejemplo n.º 1
0
    protected override void Awake()
    {
        base.Awake();

        //Check if it's unset
        if (mapSize == 0)
        {
            mapSize = DEFAULT_MAP_SIZE;
        }
        if (highlightRange == 0)
        {
            highlightRange = DEFAULT_HIGHLIGHT_RANGE;
        }

        map = mapSize == 0 ? new Map() : new Map(mapSize);

        selectedRoadType = Road.RoadType.Empty;
        inputs           = new Inputs();

        inputs.MapEditor.PlaceRoad.performed         += PlaceRoadPerformed;
        inputs.MapEditor.RotateOrientation.performed += ctx => RotateOrientation((int)ctx.ReadValue <float>());

        planeRenderer = plane.GetComponent <Renderer>();
        blockScale    = planeRenderer.bounds.size.x / map.Size;
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks if the the provided button has road of his type placed. If yes, it disable it.
 /// </summary>
 /// <param name="type">Selected road type.</param>
 /// <param name="button">Button assiociated to this type.</param>
 /// <returns>Returns if the button is interactable or not.</returns>
 public bool CheckUniqueButtonsActivation(Road.RoadType type, Button button)
 {
     button.interactable = false;
     if (map.GetRoadsOfType(type).Count == 0)
     {
         button.interactable = true;
     }
     return(button.interactable);
 }
    public static List <Road> GetRoads(OsmFile file)
    {
        List <Road> roads = new List <Road>();

        foreach (OsmWay way in file.GetWays())
        {
            List <OsmNode> nodes  = way.GetNodes();
            Vector2[]      points = new Vector2[nodes.Count];

            for (int i = 0; i < nodes.Count; i++)
            {
                points[i] = nodes[i].Coordinate;
            }

            int   lanes = 1;
            float width = 0;

            Road.RoadType roadType = Road.RoadType.Default;

            string lanesStr    = way.GetTagValue("lanes");
            string widthStr    = way.GetTagValue("width");
            string highwaysStr = way.GetTagValue("highway");

            if (lanesStr != null)
            {
                lanes = Convert.ToInt32(lanesStr);
            }

            if (widthStr != null)
            {
                width = Convert.ToSingle(widthStr, CultureInfoHelper.EnUSInfo);
            }

            if (highwaysStr != null)
            {
                roadType = Road.GetRoadType(highwaysStr);
            }

            if (roadType != Road.RoadType.Default)
            {
                roads.Add(new Road(lanes, width, points, roadType));
            }
        }

        return(roads);
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Change the selected road type.
 /// </summary>
 /// <param name="roadType">The number to use is defined in the Road.RoadType enum.</param>
 public void SelectRoadType(int roadType)
 {
     selectedRoadType = (Road.RoadType)roadType;
 }