Ejemplo n.º 1
0
    public void GenerateNewBranches()
    {
        if (branches.Count == 0)
        {
            GenerateFirstBranch();
        }
        else if (branches.Count < branchesPerTreeLimit) // TODO handle branches.Count >= 1000
        {
            List <BranchController> newBranches = new List <BranchController>();

            int branchesToGenerate = (int)System.Math.Ceiling(numberOfBranches * branchGeneratorRate);
            //Debug.Log("branchesToGenerate: " + branchesToGenerate);

            while (branchesToGenerate-- > 0)
            {
                int randomPos = UnityEngine.Random.Range(0, branches.Count);
                BranchController randomBranch = branches[randomPos];

                if (randomBranch.CanGrowSubBranches())
                {
                    GenerateBranch(randomBranch, out BranchController newBranch, out bool canBranchGenerateMore);

                    if (!canBranchGenerateMore)
                    {
                        branches.RemoveAt(randomPos);
                    }

                    if (newBranch != null)
                    {
                        newBranches.Add(newBranch);
                    }
                }
            }

            //Debug.Log($"Generated branches: {newBranches.Count}");
            //Debug.Log($"Fog destroyer radius: {fogDestroyer.radius}");
            //Debug.Log($"Total branches: {branches.Count}");

            branches.AddRange(newBranches);
        }
    }