示例#1
0
    private GameObject ShowBranch(Branch new_branch, Vector3 coordinates, Vector3 branchAngles, GameObject trunk)
    {
        GameObject branch = (GameObject)Instantiate(PrefabBranch, coordinates, PrefabBranch.transform.rotation);

        branch.name = branch.name + "-id" + new_branch.id;
        branch.transform.eulerAngles = branchAngles;
        branch.transform.SetParent(trunk.transform);

        BranchEvents branchEvents = branch.GetComponent <BranchEvents> ();

        branchEvents.branch      = new_branch;
        branchEvents.branch_name = new_branch.name;

        return(branch);
    }
示例#2
0
 /// <summary>
 /// Records a branching event
 /// </summary>
 /// <param name="ev">Event information</param>
 public void RecordBranchEvent(BranchEvent ev)
 {
     BranchEvents.Add(ev);
 }
示例#3
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));
    }