Ejemplo n.º 1
0
        public static GameObject PlaceProgressBuilding(Building building, List <UnitController> builderUnits,
                                                       int factionIndex, Position position, Quaternion rotation, ResourceManager resourceManager)
        {
            Vector3 location = PositionHelper.PositionToLocation(position);

            try
            {
                BuildingHelper.CheckValidPlacement(building, position, location, false);
            }
            catch (Exception)
            {
                // Visualizing the error placement
                if (GameManager.Instance.Debug)
                {
                    building.ClosePoints(GameManager.Instance.Grid, position.PointLocation);
                }
                throw;
            }
            for (int x = 0; x < building.cost.Length; x++)
            {
                if (building.cost[x] > 0 && resourceManager.resourceTypes[x].amount < building.cost[x])
                {
                    throw new InvalidOperationException(
                              "Not enough resources for placing the " + building + " building");
                }
            }
            for (int x = 0; x < building.cost.Length; x++)
            {
                if (building.cost[x] > 0)
                {
                    resourceManager.resourceTypes[x].amount -= building.cost[x];
                }
            }
            GameObject buildingObject;

            if (building.autoBuild)
            {
                buildingObject = BuildingHelper.InstantiateProgressBuilding(
                    building, building.obj, factionIndex, position, rotation)
                                 .gameObject;
            }
            else
            {
                buildingObject = BuildingHelper.InstantiateProgressBuilding(
                    building, building.progressObj, factionIndex, position, rotation)
                                 .gameObject;
                UnitSelection.SetTarget(builderUnits, buildingObject, buildingObject.transform.position);
            }
            return(buildingObject);
        }