// Update is called once per frame
        void Update()
        {
            if (!Minimap.MinimapInstance.minimapActive)
            {
                return;
            }

            //if player is outside and the streaming world is ready/generated for play setup building indicators.
            if (Minimap.changedLocations)
            {
                if (GameManager.Instance.PlayerGPS.HasCurrentLocation && GameManager.Instance.PlayerGPS.CurrentLocation.Loaded && GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject.Summary.LocationName != GameManager.Instance.PlayerGPS.CurrentLocation.Name)
                {
                    return;
                }

                blockArray        = null;
                buildingDirectory = null;
                //setup a new empty array based on the size of the locations child blocks. This ensures dynamic resizing for the location.
                blockArray = new DaggerfallRMBBlock[GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject.transform.childCount];
                //grab the rmbblock objects from the location object for use.
                blockArray = GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject.GetComponentsInChildren <DaggerfallRMBBlock>();
                //grab the building direction object so we can figure out what the individual buildings are based on their key value.
                buildingDirectory = GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject.GetComponentInChildren <BuildingDirectory>();
                //start to loop through blocks from the block array created above.
                CityNavigation currentCityNav = GameManager.Instance.StreamingWorld.GetCurrentCityNavigation();


                if (GameManager.Instance.IsPlayerInside || buildingDirectory == null || currentCityNav == null || buildingDirectory.BuildingCount == 0)
                {
                    Debug.Log("No Buildings/Navigation found!");
                }
                else
                {
                    currentLocation = GameManager.Instance.PlayerGPS.CurrentLocation.Name;
                    UpdateMarkers();
                    markersGenerated = false;
                }


                if (currentLocation != lastLocation)
                {
                    lastLocation         = currentLocation;
                    generatedPositionUID = GameManager.Instance.PlayerGPS.CurrentMapPixel.X + GameManager.Instance.PlayerGPS.CurrentMapPixel.Y;
                }
                else
                {
                    currentPositionUID = GameManager.Instance.PlayerGPS.CurrentMapPixel.X + GameManager.Instance.PlayerGPS.CurrentMapPixel.Y;
                    if (currentPositionUID != generatedPositionUID)
                    {
                        foreach (GameObject combinedMarker in combinedMarkerList)
                        {
                            combinedMarker.SetActive(false);
                        }
                    }
                    else if (currentPositionUID == generatedPositionUID)
                    {
                        foreach (GameObject combinedMarker in combinedMarkerList)
                        {
                            combinedMarker.SetActive(true);
                        }
                    }
                }

                Minimap.changedLocations = false;
            }

            if (generatingMarkers && !markersGenerated)
            {
                foreach (GameObject marker in buildingInfoCollection)
                {
                    if (marker.GetComponent <BuildingMarker>() != null)
                    {
                        BuildingMarker markerInstance = marker.GetComponent <BuildingMarker>();

                        if (!markerInstance.generatedMarker && markersGenerated)
                        {
                            markersGenerated = false;
                        }
                        else
                        {
                            markersGenerated = true;
                        }
                    }
                }
            }
            else if (generatingMarkers && markersGenerated)
            {
                StartCoroutine(Example());
                generatingMarkers = false;
            }
        }
        public void UpdateMarkers(bool RemoveMarkersOnly = false)
        {
            foreach (GameObject marker in buildingInfoCollection)
            {
                if (marker.GetComponent <BuildingMarker>() != null)
                {
                    BuildingMarker markerInstance = marker.GetComponent <BuildingMarker>();
                    Destroy(markerInstance.marker.attachedDoorIcon);
                    Destroy(markerInstance.marker.attachedLabel);
                    Destroy(markerInstance.marker.attachedMesh);
                    Destroy(markerInstance.marker.attachedQuestIcon);
                    Destroy(markerInstance.marker.attachedIcon);
                    Destroy(markerInstance);
                }
                if (marker != null)
                {
                    Destroy(marker);
                }
            }
            buildingInfoCollection.Clear();
            buildingInfoCollection = new List <GameObject>();

            if (RemoveMarkersOnly)
            {
                return;
            }

            generatingMarkers = true;

            //Vector3 position = currentCityNav.WorldToScenePosition(new DFPosition(Minimap.currentLocation.Summary.MapPixelX, Minimap.currentLocation.Summary.MapPixelX), true);
            List <BuildingSummary> housesForSaleList = buildingDirectory.GetHousesForSale();

            foreach (DaggerfallRMBBlock block in blockArray)
            {
                Vector3 blockPosition = block.transform.position;
                //setup a new static buildings object to hold the rmb blocks static buildings object.
                DaggerfallStaticBuildings staticBuildingContainer = block.GetComponentInChildren <DaggerfallStaticBuildings>();

                //if there are not any buildings in this block, stop code from crashing script and return.
                if (staticBuildingContainer == null)
                {
                    continue;
                }

                //resize static building array based on the number of static building pbjects in the container.
                StaticBuildingArray = new StaticBuilding[staticBuildingContainer.transform.childCount];
                //load blocks static building array into the empty array for looping through.
                StaticBuildingArray = staticBuildingContainer.Buildings;

                // Find the doors for the buildings and drop into a list for referencing below when setting up individual building information.
                StaticDoor[]           doors         = DaggerfallStaticDoors.FindDoorsInCollections(GameManager.Instance.StreamingWorld.CurrentPlayerLocationObject.StaticDoorCollections, DoorTypes.Building);
                List <CombineInstance> houseMeshList = new List <CombineInstance>();
                //runs through building array.
                foreach (StaticBuilding building in StaticBuildingArray)
                {
                    //sets up and grabes the current buildings material, summary object/info, placing/final position, game model.
                    BuildingSummary SavedBuilding = new BuildingSummary();
                    buildingDirectory.GetBuildingSummary(building.buildingKey, out SavedBuilding);

                    if (SavedBuilding.BuildingType == DFLocation.BuildingTypes.AllValid)
                    {
                        continue;
                    }

                    Vector3 markerPosition = new Vector3(0, 0, 0);

                    if (building.size.z > tallestSpot)
                    {
                        tallestSpot = building.size.z;
                    }

                    //create gameobject for building marker.
                    GameObject buildingMarkerObject = GameObjectHelper.CreateDaggerfallMeshGameObject(SavedBuilding.ModelID, null, false, null, true, false);
                    buildingMarkerObject.GetComponent <Renderer>().enabled = false;
                    buildingMarkerObject.transform.position = new Vector3(blockPosition.x + SavedBuilding.Position.x, blockPosition.y + tallestSpot + 10f, blockPosition.z + SavedBuilding.Position.z);
                    //buildingMarkerObject.SetActive(false);
                    BuildingMarker buildingsInfo = buildingMarkerObject.AddComponent <BuildingMarker>();
                    MeshRenderer   buildingMesh  = buildingMarkerObject.GetComponent <MeshRenderer>();
                    buildingsInfo.marker.attachedMesh       = buildingMarkerObject;
                    buildingMarkerObject.transform.position = buildingMarkerObject.transform.position;
                    buildingMarkerObject.transform.Rotate(SavedBuilding.Rotation);
                    buildingMarkerObject.layer = Minimap.layerMinimap;
                    buildingMarkerObject.transform.localScale = new Vector3(1, 0.01f, 1);
                    buildingMarkerObject.name               = string.Concat(SavedBuilding.BuildingType.ToString(), " Marker ", SavedBuilding.buildingKey);
                    buildingMesh.shadowCastingMode          = 0;
                    buildingMesh.lightProbeUsage            = UnityEngine.Rendering.LightProbeUsage.Off;
                    buildingMesh.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
                    //Destroy(buildingMarkerObject.GetComponent<MeshCollider>());
                    //grab and store all building info into the building marker object.
                    buildingsInfo.marker.staticBuilding  = building;
                    buildingsInfo.marker.buildingSummary = SavedBuilding;
                    buildingsInfo.marker.buildingKey     = SavedBuilding.buildingKey;

                    foreach (BuildingSummary buildingInfo in housesForSaleList)
                    {
                        if (buildingInfo.BuildingType == DFLocation.BuildingTypes.HouseForSale)
                        {
                            buildingsInfo.marker.buildingType = DFLocation.BuildingTypes.HouseForSale;
                        }
                        else
                        {
                            buildingsInfo.marker.buildingType = SavedBuilding.BuildingType;
                        }
                    }

                    buildingsInfo.marker.buildingLocation = GameManager.Instance.PlayerGPS.CurrentLocation;

                    //buildingPositionList.Add(new Vector3(block.transform.position.x + SavedBuilding.Position.x, SavedBuilding.Position.y, block.transform.position.z + SavedBuilding.Position.z));
                    buildingsInfo.marker.position = buildingMarkerObject.transform.position;

                    foreach (StaticDoor buildingsDoor in doors)
                    {
                        if (building.buildingKey == buildingsDoor.buildingKey)
                        {
                            buildingsInfo.marker.doorPosition = DaggerfallStaticDoors.GetDoorPosition(buildingsDoor);
                        }
                    }

                    //setup ref properties for quest resource locator below.
                    bool   pcLearnedAboutExistence     = false;
                    bool   receivedDirectionalHints    = false;
                    bool   locationWasMarkedOnMapByNPC = false;
                    string overrideBuildingName        = string.Empty;

                    //check if the building contains a quest using quest resouces. If found to contain a quest, mark it so.
                    if (GameManager.Instance.TalkManager.IsBuildingQuestResource(GameManager.Instance.PlayerGPS.CurrentMapID, buildingsInfo.marker.buildingKey, ref overrideBuildingName, ref pcLearnedAboutExistence, ref receivedDirectionalHints, ref locationWasMarkedOnMapByNPC))
                    {
                        Minimap.lastQuestMarkerPosition  = buildingsInfo.marker.position;
                        buildingsInfo.marker.questActive = true;
                    }
                    //save building to building collection. This is more for other modders to use how they wish, since it contains all the building info for every building in a city.
                    buildingInfoCollection.Add(buildingMarkerObject);
                }
            }
            markersGenerated = true;
        }