Ejemplo n.º 1
0
    private GameObject ShowTrunk(Trunk new_trunk, Vector3 coordinates, GameObject tree)
    {
        GameObject trunk = (GameObject)Instantiate(PrefabTrunk, coordinates, PrefabTrunk.transform.rotation);

        trunk.name = trunk.name + "-id" + new_trunk.id;
        trunk.transform.SetParent(tree.transform);

        TrunkEvents trunkEvents = trunk.GetComponent <TrunkEvents> ();

        trunkEvents.trunk      = new_trunk;
        trunkEvents.trunk_name = new_trunk.name;

        return(trunk);
    }
Ejemplo n.º 2
0
    public IEnumerator ShowForest()
    {
        Trunk       temporalTrunk = null;
        Branch      temporalBranch = null;
        GameObject  currentTree = null, currentTrunk = null, currentBranch = null;
        TrunkEvents existingTrunk = null;
        Vector3     trunkCoordinates = Vector3.zero, branchCoordinates = Vector3.zero, branchAngles = Vector3.zero;

        foreach (Leaf leaf in leaves)
        {
            foreach (Branch branch in leaf.branchs)
            {
                // print (leaf.name + " # " + branch.name + " > " + branch.trunk.name);

                if (temporalTrunk == null || temporalTrunk.id != branch.trunk.id)
                {
                    if (currentTrunk != null)
                    {
                        existingTrunk = FindExistingTrunk(branch.trunk);
                    }

                    if (existingTrunk == null)
                    {
                        trunkCoordinates = GenerateTrunkCoordinates();

                        currentTree  = ShowTree(trunkCoordinates);
                        currentTrunk = ShowTrunk(branch.trunk, trunkCoordinates, currentTree);

                        temporalTrunk = branch.trunk;
                    }
                    else
                    {
                        trunkCoordinates = existingTrunk.transform.position;

                        currentTrunk  = existingTrunk.gameObject;
                        temporalTrunk = branch.trunk;
                    }
                }

                if (temporalBranch == null || temporalBranch.id != branch.id)
                {
                    BranchEvents existingBranch = FindExistingBranch(currentTrunk, branch);

                    if (existingBranch == null)
                    {
                        branchCoordinates = GenerateBranchCoordinates(trunkCoordinates);
                        branchAngles      = GenerateBranchRotation();

                        currentBranch  = ShowBranch(branch, branchCoordinates, branchAngles, currentTrunk);
                        temporalBranch = branch;
                    }
                    else
                    {
                        branchCoordinates = existingBranch.transform.position;
                        branchAngles      = existingBranch.transform.eulerAngles;

                        currentBranch  = existingBranch.gameObject;
                        temporalBranch = branch;
                    }
                }

                ShowLeaf(leaf, GenerateLeafCoordinates(branchCoordinates), branchAngles, currentBranch);
            }

            JoinByLiana(leaf);
        }
        SetStatus(StatusBuildTree.Idle);
        RemoveSpinner();
        yield return(new WaitForSeconds(1f));
    }