Exemple #1
0
 public void RandomPickPhotos(MushroomScriptableObject mushScrObj, List <Texture> textures)
 {
     Texture[] texturesArray = textures.ToArray();
     mushScrObj.Photos = AuxiliarFunctions.RandomPickWithoutRepetition(texturesArray, 4);
     EditorUtility.SetDirty(mushScrObj);
     AssetDatabase.SaveAssets();
 }
Exemple #2
0
        /// <summary>
        /// Places mushrooms for a group of trees.
        /// </summary>
        /// <param name="treesFromGroup">List of trees to place mushrooms around</param>
        private void SpawnMushroomsFromGroup(List <GameObject> treesFromGroup)
        {
            if (IsMushroomLimitReached())
            {
                return;
            }
            float[] mushroomsProbabilities;
            // Choose posible mushrooms to spawn in this group of trees (random at the moment)
            mushroomsProbabilities = posibleMushrooms.GetProbabilities();
            mushroomsChosen        = ChooseSet(mushroomsProbabilities, maxMushroomChosen);
            if (mushroomsChosen.Length < 1)
            {
                return;
            }

            // Run through trees from the group
            foreach (GameObject tree in treesFromGroup)
            {
                if (IsMushroomLimitReached())
                {
                    return;
                }
                //Choose posible points around to spawn
                spawnPoints = GetPointsAround(tree.transform.position, spawnMaxRadius, spawnMinRadius, pointsAroundTrees);

                spawnPointsChosen = AuxiliarFunctions.RandomPickWithoutRepetition(spawnPoints, maxPointsChosen);
                foreach (Vector3 vec3 in spawnPointsChosen)
                {
                    // Choose a mushroom index (or not) from chosen mushrooms to spawn in the point
                    float[] mushroomsChosenProbabilities = mushroomsChosen.GetProbabilities();
                    int     index = Choose(mushroomsChosenProbabilities);
                    if (index != -1)
                    {
                        // Spawn the mushroom if one is chosen with random rotation
                        if (IsMushroomLimitReached())
                        {
                            return;
                        }
                        SpawnMushroom(mushroomsChosen[index].prefab, vec3);
                    }
                }
            }
        }