コード例 #1
0
ファイル: BuildingTab.cs プロジェクト: beatt2/FoodGame
        private void SetButton(Button button, BuildingPrefab prefab)
        {
            StatBar statBar = button.gameObject.transform.parent.GetComponentInChildren <StatBar>();

            if (statBar == null)
            {
                return;
            }
            for (int i = 0; i < prefab.Happiness; i++)
            {
                statBar.Happiness[i].gameObject.SetActive(true);
            }

            for (int i = 0; i < prefab.EnviromentValue; i++)
            {
                statBar.Enviroment[i].gameObject.SetActive(true);
            }

            float onePercent = _highestPrice / 100;
            int   moneyValue = prefab.MyBuilding.BuildPrice / (int)onePercent;
            int   finalValue = moneyValue / 10;

            for (int i = 0; i < finalValue; i++)
            {
                statBar.Money[i].gameObject.SetActive(true);
            }
        }
コード例 #2
0
    public Building(BuildingPrefab prefab, bool isStartingBuilding = false)
    {
        Height = prefab.Height;
        Width  = prefab.Width;

        FloorTiles         = new GameObject[Height, Width];
        WallTiles          = new GameObject[Height, Width];
        Props              = new Prop[Height, Width];
        AddedDoorLocations = new char[Height, Width];

        PickTilePrefabs();

        Blueprint = prefab.Blueprint;

        Build();
        PlaceExteriorDoorOnRandomSide();

        if (isStartingBuilding)
        {
            var ovenPrefab = WorldData.Instance.PizzaOven;
            Props[2, 1] = new Furniture("pizza oven", ovenPrefab);
            Furnish(true);
        }
        else
        {
            Furnish();
        }
    }
コード例 #3
0
        public static void UpgradeFarmFinished(BuildingPrefab buildingPrefab)
        {
            var node = buildingPrefab.GetComponent <NodeBehaviour>();

            node.SetSprite(SaveManager.Instance.GetSprite(buildingPrefab.GetSavedBuilding().SpriteIndex));

            buildingPrefab.RemoveUpgrade();
        }
コード例 #4
0
    private void LoadPrefabsFromFile()
    {
        var rawPrefabInfo = BuildingPrefabFile.text.Split("\r\n"[0]).ToList();

        var currentStep = LoadingSteps.AddKey;

        var currentPreFab = string.Empty;

        var numColumns = 0;

        var x = 0;

        foreach (var line in rawPrefabInfo)
        {
            var trimmedLine = line.Trim('\n');
            if (string.IsNullOrEmpty(trimmedLine))
            {
                currentStep = LoadingSteps.AddKey;
                continue;
            }

            if (currentStep == LoadingSteps.AddKey)
            {
                if (BuildingPrefabs.ContainsKey(trimmedLine))
                {
                    Debug.Log("Building template already exists in _buildingPrefabs!");
                    continue;
                }
                BuildingPrefabs.Add(trimmedLine, null);
                currentPreFab = trimmedLine;
                currentStep   = LoadingSteps.Dimensions;
                x             = 0;
                continue;
            }

            if (currentStep == LoadingSteps.Dimensions)
            {
                var dimensions = trimmedLine.Split(' ');
                var numRows    = int.Parse(dimensions[0]);
                numColumns = int.Parse(dimensions[1]);
                BuildingPrefabs[currentPreFab] = new BuildingPrefab(new char[numRows, numColumns]);
                currentStep = LoadingSteps.Template;
                continue;
            }

            if (currentStep == LoadingSteps.Template)
            {
                for (var currentColumn = 0; currentColumn < numColumns; currentColumn++)
                {
                    var row = BuildingPrefabs[currentPreFab].Blueprint;

                    row[x, currentColumn] = trimmedLine[currentColumn];
                }
                x++;
            }
        }
    }
コード例 #5
0
 public void BuildBuilding(BuildingPrefab building)
 {
     if (CurrentBuilding != null && TileManager.instance.buildingDictionary.TryGetBuilding(CurrentBuilding, out BuildingPrefab existingBuilding))
     {
         DailyResources -= existingBuilding.DailyResources;
         //StockPiledResources -= existingBuilding.StockPiledResources;
         MaxStockPile -= existingBuilding.MaxStockPile;
     }
     CurrentBuilding = building.name;
     DailyResources += building.DailyResources;
     //StockPiledResources += building.StockPiledResources;
     MaxStockPile += building.MaxStockPile;
     Destroy(Graphics.gameObject);
     Graphics = Instantiate(building, transform);
 }
コード例 #6
0
 public bool TryGetBuilding(string name, out BuildingPrefab building)
 {
     return(BuildingPairs.TryGetValue(name, out building));
 }