public static void CreateRoof(OsmWay buildingData, OsmBounds bounds, float height, Transform parent)
        {
            GameObject roof = OsmMeshFactory.CreateMesh(buildingData, bounds);

            roof.transform.localPosition = new Vector3(roof.transform.localPosition.x, height, roof.transform.localPosition.z);
            roof.name = "roof";

            if (ConfigManager.Instance.Textures)
            {
                bool colorSet = false;
                if (buildingData.Tags.ContainsKey(TagKeyEnum.RoofColour))
                {
                    var colorString = buildingData.Tags[TagKeyEnum.RoofColour].Replace("#", "");
                    colorSet = SetColor(colorString, roof.GetComponent <Renderer>().material);
                    colorSet = true;
                }
                if (!colorSet)
                {
                    string materiaName = string.Format("{0}/{1}_{2}",
                                                       Constants.Constants.MaterialsFolderName,
                                                       "roof", new System.Random().Next(BuildingsConstants.firstIndexRandomRoof, BuildingsConstants.endIndexRandomRoof));

                    Material material = Resources.Load(materiaName, typeof(Material)) as Material;
                    roof.GetComponent <Renderer>().material = material;
                }
            }


            roof.transform.parent = parent;
        }
Esempio n. 2
0
        public static void CreateArea(OsmWay areaData, OsmBounds bounds, Transform parent)
        {
            Material material = null;

            if (ConfigManager.Instance.Textures)
            {
                if (areaData.Tags.ContainsKey(TagKeyEnum.Landuse))
                {
                    Enums.LanduseTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions.GetTagKeyEnum <Enums.LanduseTypeEnum>(areaData.Tags[TagKeyEnum.Landuse]);
                    if (type != Enums.LanduseTypeEnum.None)
                    {
                        string materiaName = string.Format("{0}/{1}_{2}",
                                                           Constants.Constants.MaterialsFolderName,
                                                           OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(TagKeyEnum.Landuse),
                                                           OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(type));

                        material = Resources.Load(materiaName, typeof(Material)) as Material;
                    }
                }
                if (areaData.Tags.ContainsKey(TagKeyEnum.Leisure))
                {
                    Enums.LeisureTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions.GetTagKeyEnum <Enums.LeisureTypeEnum>(areaData.Tags[TagKeyEnum.Leisure]);
                    if (type != Enums.LeisureTypeEnum.None)
                    {
                        string materiaName = string.Format("{0}/{1}_{2}",
                                                           Constants.Constants.MaterialsFolderName,
                                                           OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(TagKeyEnum.Leisure),
                                                           OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(type));

                        material = Resources.Load(materiaName, typeof(Material)) as Material;
                    }
                }

                if (areaData.Tags.ContainsKey(TagKeyEnum.Amenity))
                {
                    Enums.AmenityTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions.GetTagKeyEnum <Enums.AmenityTypeEnum>(areaData.Tags[TagKeyEnum.Amenity]);
                    if (type != Enums.AmenityTypeEnum.None)
                    {
                        string materiaName = string.Format("{0}/{1}_{2}",
                                                           Constants.Constants.MaterialsFolderName,
                                                           OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(TagKeyEnum.Amenity),
                                                           OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(type));

                        material = Resources.Load(materiaName, typeof(Material)) as Material;
                    }
                }

                if (material != null)
                {
                    GameObject result = OsmMeshFactory.CreateMesh(areaData, bounds);
                    if (areaData.Tags.ContainsKey(TagKeyEnum.Name))
                    {
                        result.name = areaData.Tags[TagKeyEnum.Name];
                    }
                    else
                    {
                        result.name = "landuse";
                    }
                    result.GetComponent <Renderer>().material = material;
                    result.transform.parent = parent;
                }
            }
        }