コード例 #1
0
ファイル: TREE.cs プロジェクト: dlobser/Sugar
        public void recursiveBranch(Genome g, int counter, GameObject joint)
        {
            GameObject newBranch, kidJoint;

            int end = (int)g.end [counter];

            if ((int)g.end [counter] == -1)
            {
                end = joint.GetComponent <Joint> ().joints + 1;
            }

            if (joint.GetComponent <Joint> ().joints < end)
            {
                end = joint.GetComponent <Joint> ().joints + 1;
            }

            for (int i = (int)g.start[counter]; i < end; i += (int)g.divs[counter])
            {
                kidJoint      = TREEUtils.findJointOnBranch(joint, i);
                kidJoint.name = "branchRoot_" + i;

                int[] jcounter = { ++jCounter };

                for (int j = 0; j < (int)g.rads[counter]; j++)
                {
                    Trait t = new Trait();
                    t.Apply(trait);

                    t.offset  = kidJoint.gameObject.GetComponent <Joint> ().joint;
                    t.offset2 = j;

                    t.jointScale = g.length [counter];

                    newBranch = Branch((int)g.joints [counter] - 1, t);
                    newBranch.transform.parent = kidJoint.transform;
                    TREEUtils.zeroTransforms(newBranch);
                    newBranch.transform.localEulerAngles = (new Vector3(0, j * 360 / g.rads [counter], g.angles [counter]));
                    newBranch.transform.localPosition    = (new Vector3(0, kidJoint.GetComponent <Joint> ().trait.jointScale, 0));
                    kidJoint.GetComponent <Joint> ().limbs.Add(newBranch);
                }
                if (counter + 1 < g.joints.Length)
                {
                    for (int k = 0; k < (int)kidJoint.GetComponent <Joint> ().limbs.Count; k++)
                    {
                        recursiveBranch(g, counter + 1, kidJoint.GetComponent <Joint> ().limbs [k]);
                    }
                }
            }
        }