/// <summary> /// Adds a MapPlaceable to the placedBuildingDictionary /// </summary> /// <param name="placedObject"></param> /// <returns></returns> public void AddMapPlaceable(SimpleMapPlaceable placedObject) { if (!placedObject) { return; } Vector3 placedPosition = TransformPosition(placedObject.transform.position); for (int i = 0; i < placedObject.UsedCoordinates.Count; i++) { Vector3 occupiedSpace = placedPosition + placedObject.UsedCoordinates[i].UsedCoordinate; if (!_placedBuildingDictionary.ContainsKey(occupiedSpace)) { _placedBuildingDictionary.Add(occupiedSpace, placedObject); // Debug.Log("BuildingManager Added: " + placedObject.name + " at " + occupiedSpace); } else { // Remove all previously added entries for (int removeIndex = i; removeIndex > 0; removeIndex--) { Vector3 removedSpace = TransformPosition(placedObject.transform.position) + placedObject.UsedCoordinates[removeIndex].UsedCoordinate; _placedBuildingDictionary.Remove(removedSpace); } return; } } // placedObject.transform.position = placedPosition + (Vector3.one / 2f); placedObject.OnPlacement(); }
// private int CountNeighbors(Street street) // { // int count = 0; // foreach (PathFindingNode neighborNode in street.NeighborNodes) // { // if (!neighborNode) continue; // count++; // } // // return count; // } private SimpleMapPlaceable PlaceStreetAt(Vector3 position) { GameObject gameObject = Instantiate(_streetData.Prefab); SimpleMapPlaceable simpleMapPlaceable = gameObject.GetComponent <SimpleMapPlaceable>(); gameObject.transform.position = position; simpleMapPlaceable.OnPlacement(); _placementController.PlaceObject(simpleMapPlaceable); _cityPlaceable.ChildMapPlaceables.Add(simpleMapPlaceable); gameObject.transform.SetParent(transform); return(simpleMapPlaceable); }