public void GenerateTiles()
        {
            string CurrentDirectroy = Directory.GetCurrentDirectory();

            foreach (UI_Tile uiTile in SeedCollection.UI_Tile)
            {
                //for (int i = 0; i < uiTile.SeedSprites.Length; i++)
                //{
                Tile seedGestationTile = ScriptableObject.CreateInstance <LazyTile>(); // new Tile();
                seedGestationTile.name   = $"{uiTile.Name}";
                seedGestationTile.sprite = uiTile.GetSprite();                         //seedGestationSprite;
                allUITiles.Add(seedGestationTile);
                //}
            }

            foreach (Seed seed in SeedCollection.Seed)
            {
                for (int i = 0; i < seed.GetSprites().Count; i++)
                {
                    LazyTile seedGestationTile = ScriptableObject.CreateInstance <LazyTile>(); // new Tile();
                    seedGestationTile.name   = $"{seed.Name}_{seed.GetSprites()[i]}";
                    seedGestationTile.sprite = seed.GetSprites()[i];                           //seedGestationSprite;
                    seedGestationTile.Seed   = seed;
                    allSeedTiles.Add(seedGestationTile);
                }
            }
        }
Beispiel #2
0
        public LazyTile GetNextTile()
        {
            ACC++;
            if (ACC > this.CurrentTiles.Length - 2)
            {
                ACC = 0;
                return(null);
            }

            LazyTile lazyTile = this.CurrentTiles[ACC];

            return(lazyTile);
        }
Beispiel #3
0
        private void HandleLazyTileSelection(Tilemap tM, Vector3Int newPosition)
        {
            FarmableObject currentFarmableObjectAtTile = null;
            Seed           selectedSeed = FarmerPlayer.instance.GetSelectedSeed();

            if (selectedSeed == null)
            {
                return;
            }

            List <LazyTile> allPossibleTilesGivenSelectedSeed = this.Seed_Tiles.Where(x => x.Seed == selectedSeed).ToList();



            bool hasTileAtPosition           = tM.HasTile(newPosition);
            bool hasFarmableObjectAtPosition = FarmableObjects.ContainsKey(newPosition);
            //TODO - seems weird.

            IEnumerable <Seed> seedsAvailable =
                Inventory.instance.Items.Where(x => x._InventoryItemScriptable != null)
                .Select(s => s._InventoryItemScriptable)
                .Where(x => x.Seed != null && x.Seed == selectedSeed)
                .Select(z => z.Seed);



            if (!seedsAvailable.Any())
            {
                Debug.Log($"Seed of type {selectedSeed.Name} is empty. You cannot add anymore.");
                return;
            }

            //till the soil
            this.Tilemaps[1].SetTile(newPosition, UI_Tiles.First(x => x.name == "Tilled"));

            //Retrieve or create new farmable object
            if (!hasFarmableObjectAtPosition)
            {
                currentFarmableObjectAtTile          = Instantiate(this._farmableObject);
                currentFarmableObjectAtTile.Position = newPosition; // redundant
                currentFarmableObjectAtTile.transform.SetParent(this.transform);
                currentFarmableObjectAtTile.Seed         = selectedSeed;
                currentFarmableObjectAtTile.CurrentTiles = allPossibleTilesGivenSelectedSeed.ToArray();
                FarmableObjects.Add(newPosition, currentFarmableObjectAtTile);
            }
            else
            {
                currentFarmableObjectAtTile = FarmableObjects[newPosition];
            }


            //Add or Update Current Tile at position
            if (!hasTileAtPosition)
            {
                //tM.SetTile(newPosition, lazyT);
                tM.SetTile(newPosition, currentFarmableObjectAtTile.GetCurrentTile());
                Inventory.instance.RemoveInventoryItem(selectedSeed, 1);
                //FarmerPlayer.instance.Backpack.RemoveSeed(selectedSeed.SeedType, 1);
            }
            else
            {
                LazyTile t = tM.GetTile(newPosition) as LazyTile;
                if (t.Seed == currentFarmableObjectAtTile.Seed)
                {
                    tM.SetTile(newPosition, null);
                    LazyTile nextTile = currentFarmableObjectAtTile.GetNextTile();
                    if (nextTile != null)
                    {
                        tM.SetTile(newPosition, nextTile);
                    }
                }
                else
                {
                    Debug.Log("Wrong seed on current tile v. selected tile.");
                }
            }
        }