Ejemplo n.º 1
0
        /// <summary>
        /// Function to destroy a particular building.
        /// </summary>
        /// <param name="visualizedObject"></param>
        /// <param name="destroyEffect">Set this to true if you want the building to disappear with a nice effect</param>
        public void DestroyBuilding(IVisualizedBuilding visualizedObject, bool destroyEffect = true)
        {
            if (visualizedObject.GameObject == null)
            {
                return;
            }

            // Get the correct tile from the grid
            List <KeyValuePair <Tile, TileObject> > gridObjects = Grid.Where(t =>
                                                                             t.Value != null && t.Value.GameObject != null &&
                                                                             t.Value.GameObject.Equals(visualizedObject.GameObject)).ToList();

            foreach (KeyValuePair <Tile, TileObject> gridObject in gridObjects)
            {
                // Check if we want a destroy effect or not
                if (visualizedObject is VisualizedStagingBuildingModel || !destroyEffect)
                {
                    Destroy(visualizedObject.GameObject);
                }
                else
                {
                    visualizedObject.GameObject.AddComponent <DestroyGridTile>().Tile = gridObject.Key;
                }
                // Set the tile to null
                Grid[gridObject.Key] = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to remove the first building of a neighbourhood. This only happens in-game, no API calls involved!
        /// </summary>
        /// <param name="serviceName"></param>
        public void RemoveBuilding(string serviceName)
        {
            NeighbourhoodModel  neighbourhood = CityManager.Instance.GameModel.Neighbourhoods.FirstOrDefault(x => x.Name == serviceName);
            IVisualizedBuilding building      =
                (IVisualizedBuilding)neighbourhood?.VisualizedObjects.FirstOrDefault(x => x is IVisualizedBuilding);

            if (building != null)
            {
                ApiManager.Instance.ApiUpdateEvent?.Invoke(new UpdateEventModel
                {
                    RemovedVisualizedObject = building.Identifier
                });
            }
        }