Ejemplo n.º 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();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Unity method that draws Gizmo elements on the scene editor.
 /// </summary>
 protected override void OnDrawGizmosSelected()
 {
     if (drawDebugRadius)
     {
         Transform t = GetComponent <Transform>();
         AuxiliarFunctions.DrawCircleGizmo(t, treeRadius, mushroomRadius);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Unity method that draws Gizmo elements on the scene editor.
 /// </summary>
 protected virtual void OnDrawGizmosSelected()
 {
     if (drawDebugRadius)
     {
         Transform t = GetComponent <Transform>();
         AuxiliarFunctions.DrawCircleGizmo(t, treeRadius);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets a number of random points around a certain position within a min and max radius.
 /// </summary>
 /// <param name="position">Position to choose around</param>
 /// <param name="maxRadius">Maximum radius to get points around</param>
 /// <param name="minRadius">Minimum radius to get points around</param>
 /// <param name="maxPoints">Maximum number of points obtained</param>
 /// <returns>The random points obtained</returns>
 private Vector3[] GetPointsAround(Vector3 position, float maxRadius, float minRadius, int maxPoints)
 {
     Vector3[] points = new Vector3[maxPoints];
     for (int i = 0; i < maxPoints; i++)
     {
         points[i] = AuxiliarFunctions.PickRandomPosAroundPoint(position, maxRadius, terrainUsed, minRadius);
     }
     return(points);
 }
Ejemplo n.º 5
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);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Calculates a position in the scene for a new basket raycasting to the floor from an initial posible position.
        /// Takes care of not being too close of an environment object.
        /// </summary>
        /// <param name="defaultPosition">A posible initial position</param>
        /// <returns>The calculated position</returns>
        private Vector3 CalculateNewBasketPosition(Vector3 defaultPosition)
        {
            RaycastHit hit;
            Vector3    targetLocation;

            // Check downwards or upwards to get a position in the floor
            if (Physics.Raycast(defaultPosition, Vector3.down, out hit, Mathf.Infinity, FloorMask) ||
                Physics.Raycast(defaultPosition, Vector3.up, out hit, Mathf.Infinity, FloorMask))
            {
                targetLocation = hit.point;
                // While not getting a position clear of nearby environment objects, keep looking for a position
                while (AuxiliarFunctions.CheckObjectsAround(targetLocation, checkObjectsRadius, EnvironmentMask))
                {
                    targetLocation = AuxiliarFunctions.PickRandomPosAroundPoint(hit.point, pickPointRadius);
                }
            }
            else
            {
                Debug.LogError("NoFloortHit");
                targetLocation = new Vector3(defaultPosition.x, 0f, defaultPosition.z);
            }
            return(targetLocation);
        }
Ejemplo n.º 7
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            MushroomScriptableObject mushScrObj = (MushroomScriptableObject)target;

            if (GUILayout.Button("Random pick photos"))
            {
                string sDataPath           = Application.dataPath;
                string capitalizedMushName = AuxiliarFunctions.FirstUpper(mushScrObj.Name);
                string sFolderPath         = sDataPath.Substring(0, sDataPath.Length - 6) + "Assets/Art/2D/Mushrooms/" + capitalizedMushName;
                Debug.Log("A: " + sFolderPath);
                string[]       aFilePaths = Directory.GetFiles(sFolderPath, "*.jpg");
                List <Texture> textures;
                textures = new List <Texture>();
                foreach (string sFilePath in aFilePaths)
                {
                    string sAssetPath = sFilePath.Substring(sDataPath.Length - 6);
                    Object objAsset   = AssetDatabase.LoadAssetAtPath(sAssetPath, typeof(Object));
                    textures.Add((Texture2D)objAsset);
                }
                RandomPickPhotos(mushScrObj, textures);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Instantiates and places a random tree from posible trees on a random position inside placement radius.
        /// </summary>
        /// <param name="hierarchyGroup">Hierarchy element to make the instantiated tree child of it</param>
        /// <returns></returns>
        protected GameObject SpawnTree(Transform hierarchyGroup)
        {
            Vector3    pos;
            Quaternion rot;
            GameObject tmp;
            RaycastHit hit;
            GameObject go = posibleTrees[Random.Range(0, posibleTrees.Length)];

            pos = Random.insideUnitCircle * treeRadius;
            pos.Set(pos.x + transform.position.x, 30f, pos.y + transform.position.z);
            rot = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
            if (AuxiliarFunctions.RaycastDownToFloor(pos, out hit))
            {
                tmp = Instantiate(go, hit.point, rot);
            }
            else
            {
                Debug.LogError("NoTreeHit. Tree pos below terrain. Assigning new pos with y=0. Further errors expected");
                tmp = Instantiate(go, new Vector3(pos.x, 0f, pos.y), rot);
            }
            tmp.transform.SetParent(hierarchyGroup);
            instantiatedTrees.Add(tmp);
            return(tmp);
        }