public Building(Way _way, BuildingConfigurations config, Material mat, int materialID, float texWidth)
        {
            type = buildingType.standard;
            way = _way;

            id = way.id;

            buildingConfig = config;
            buildingHeight = getBuildingHeight(way.tags);
            equalizedBuildingHeight = assingBuildingTopLevel(way);

            defaultMaterial = mat;
            defaultMaterialID = materialID;
            defaultTextureWidth = texWidth;
            facadeSkins = new List<FacadeSkin>();

            isClockwise = getWayOrientation(way);

            building = new GameObject("building" + id);
            building.transform.position = new Vector3(0.0f, 0.0f, 0.0f);

            GOtransform = new Vector3(0, 0, 0);
            GOrotate = new Vector3(0, 0, 0);
            GOscale = new Vector3(1, 1, 1);
        }
        public BuildingListModeller(List<Way> buildingWay, List<BuildingRelation> buildingRelation, BuildingConfigurations config, List<BuildingSave> buildingSave)
        {
            setMaterialList(config);

            buildingList = new List<Building>();

            for (int i = 0; i < buildingRelation.Count; i++)
            {
                int saveIndex = buildingSave.FindIndex(item=> item.buildingID == buildingRelation[i].id);
                if (saveIndex == -1)
                    continue;
                float materialtexWidth = 10;
                int materialID = buildingSave[saveIndex].materialID;
                Material mat = getMaterial(materialID,config,ref materialtexWidth);
                try
                {

                    buildingList.Add(new Building(buildingRelation[i], config, mat, materialID, materialtexWidth));
                    buildingList[buildingList.Count - 1].facadeSkins = new List<FacadeSkin>(buildingSave[saveIndex].skins);
                }
                catch (Exception ex)
                {
                    Debug.Log("<color=red>Building ERROR:</color>" + ex.Message);
                    continue;
                }
            }

            for (int i = 0; i < buildingWay.Count; i++)
            {
                if (!buildingList.Exists(item => item.id == buildingWay[i].id))
                {
                    int saveIndex = buildingSave.FindIndex(item => item.buildingID == buildingWay[i].id);
                    if (saveIndex == -1)
                        continue;
                    float materialtexWidth = 10;
                    int materialID = buildingSave[saveIndex].materialID;
                    Material mat = getMaterial(materialID, config, ref materialtexWidth);
                    try
                    {
                        buildingList.Add(new Building(buildingWay[i], config, mat, materialID, materialtexWidth));
                        buildingList[buildingList.Count - 1].facadeSkins = new List<FacadeSkin>(buildingSave[saveIndex].skins);
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("<color=red>Building ERROR:</color>" + ex.Message);
                        continue;
                    }
                }
            }
        }
        public BuildingListModeller(List<Way> buildingWay, List<BuildingRelation> buildingRelation, BuildingConfigurations config)
        {
            setMaterialList(config);

            buildingList = new List<Building>();

            for (int i = 0; i < buildingRelation.Count; i++)
            {
                float materialtexWidth = 10;
                int materialID = -1;
                Material mat = getMaterial(buildingRelation[i].tags, config, ref materialtexWidth, ref materialID);
                try
                {
                    buildingList.Add(new Building(buildingRelation[i], config, mat, materialID, materialtexWidth));
                }
                catch (Exception ex)
                {
                    Debug.Log("<color=red>Building ERROR:</color>" + ex.Message);
                    continue;
                }
            }

            for (int i = 0; i < buildingWay.Count; i++)
            {
                if(!buildingList.Exists(item => item.id == buildingWay[i].id))
                {
                    float materialtexWidth = 10;
                    int materialID = -1;
                    Material mat = getMaterial(buildingWay[i].tags, config, ref materialtexWidth, ref materialID);
                    try
                    {
                        buildingList.Add(new Building(buildingWay[i], config, mat, materialID, materialtexWidth));
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("<color=red>Building ERROR:</color>" + ex.Message);
                        continue;
                    }
                }

            }
        }
        private void setMaterialList(BuildingConfigurations buildingConfig)
        {
            materialList = new List<Material>();

            for (int k = 0; k < buildingConfig.defaultSkins.Count; k++)
            {
                BuildingMaterial bmat = buildingConfig.defaultSkins[k];
                Material mat = InGameTextureHandler.createMaterial2(bmat.colorTexturePath, bmat.normalTexturePath, bmat.specularTexturePath);
                materialList.Add(mat);
            }
        }
 private Material getMaterial(int materialID, BuildingConfigurations config, ref float matWidth)
 {
     matWidth = config.defaultSkins[materialID].width;
     return materialList[materialID];
 }
        private Material getMaterial(List<Tag> tagList, BuildingConfigurations config, ref float matWidth, ref int matID)
        {
            int skinindex;

            for (int i = 0; i < tagList.Count; i++)
            {
                if (tagList[i].k == "man_made" && tagList[i].v == "tower")
                {
                    skinindex = config.defaultSkins.FindIndex(item=> item.name == "Antic Stones");
                    matWidth = config.defaultSkins[skinindex].width;
                    matID = skinindex;
                    return materialList[skinindex];
                }
                if (tagList[i].k == "shop" && tagList[i].v == "kiosk")
                {
                    skinindex = config.defaultSkins.FindIndex(item => item.name == "Kiosk");
                    matWidth = config.defaultSkins[skinindex].width;
                    matID = skinindex;
                    return materialList[skinindex];
                }
            }

            do
            {
                skinindex = UnityEngine.Random.Range(0, config.defaultSkins.Count);
            }
            while (!config.defaultSkins[skinindex].isActive);

            matWidth = config.defaultSkins[skinindex].width;
            matID = skinindex;
            return materialList[skinindex];
        }
        public void clickSave()
        {
            InitialConfigLoader loader = new InitialConfigLoader();
            InitialConfigurations config = loader.loadInitialConfig();

            //Create new Building Config Part
            BuildingConfigurations newbuildingconfig = new BuildingConfigurations();

            InputField min = buildingMenu.transform.Find("Panel").Find("HeightComponent").Find("InputField_Min").GetComponent<InputField>();
            newbuildingconfig.minheight = float.Parse(min.text);
            InputField max = buildingMenu.transform.Find("Panel").Find("HeightComponent").Find("InputField_Max").GetComponent<InputField>();
            newbuildingconfig.maxheight = float.Parse(max.text);
            newbuildingconfig.defaultSkins = materialList;

            Transform contentPanel = buildingMenu.transform.Find("Panel").Find("ScrollRect").Find("Content Panel");
            int index = 0;
            foreach (Transform child in contentPanel)
            {
                Toggle t=  child.Find("Panel").Find("Toggle").GetComponent<Toggle>();
                newbuildingconfig.defaultSkins[index].isActive = t.isOn;
                index++;
            }

            config.buildingConfig = newbuildingconfig;

            loader.saveInitialConfig(Path.Combine(Application.persistentDataPath, "ConfigFiles/initialConfig.xml"), config);

            buildingMenu.SetActive(false);
        }
        public Building(BuildingRelation _relation, BuildingConfigurations config, Material mat,int materialID, float texWidth)
        {
            type = buildingType.withholeInside;
            relation = _relation;

            id = relation.outerWall.id;

            buildingConfig = config;
            buildingHeight = getBuildingHeight(relation.tags);
            equalizedBuildingHeight = assingBuildingTopLevel(relation.outerWall);

            isClockwise = getWayOrientation(relation.outerWall);

            defaultMaterial = mat;
            defaultMaterialID = materialID;
            defaultTextureWidth = texWidth;
            facadeSkins = new List<FacadeSkin>();

            building = new GameObject("building" + id);
            building.transform.position = new Vector3(0.0f, 0.0f, 0.0f);

            GOtransform = new Vector3(0, 0, 0);
            GOrotate = new Vector3(0, 0, 0);
            GOscale = new Vector3(1, 1, 1);
        }