예제 #1
0
    };                                            //2d array, where each item is a layer

    public void addNextLayer()
    {
        //Debug.Log("adding next Layer");

        if (bobbles.Count >= layerCount.Count)
        {
            return;
        }
        ArrayList prevLayer;

        if (bobbles.Count == 0)
        {
            //Debug.Log("bobbles.Count == 0");
            prevLayer = new ArrayList {
                firstBobble
            };
        }
        else
        {
            //Debug.Log("bobbles.Count != 0");
            prevLayer = (ArrayList)bobbles[bobbles.Count - 1];
        }

        ArrayList newLayer = new ArrayList {
        };

        foreach (GameObject bobble in prevLayer)
        {
            for (int i = 0; i < (int)layerCount[bobbles.Count]; i++)
            {
                GameObject newBobble = GameObject.Instantiate(firstBobble);
                newBobble.transform.position              = bobble.transform.position;
                newBobble.GetComponent <Grow>().maxSize   = bobble.GetComponent <Grow>().maxSize *(sizeN / sizeD);
                newBobble.GetComponent <Rigidbody>().mass = bobble.GetComponent <Rigidbody>().mass *(sizeN / sizeD) * (sizeN / sizeD) * (sizeN / sizeD);
                newBobble.GetComponent <Grow>().makeSmall();                                                            //set maxsize here
                newBobble.GetComponent <SpringJoint>().connectedBody = bobble.GetComponent <Rigidbody>();
                newBobble.GetComponent <SpringJoint>().spring        = 100 * newBobble.GetComponent <Rigidbody>().mass; //make spring strength proportional to mass
                newBobble.GetComponent <Grow>().motherTree           = this;

                //make a random brown color
                Material newMat = new Material(mat);
                newMat.color = MyColors.Varient(bobble.GetComponent <Renderer>().material.color, generalVar);
                newBobble.GetComponent <Renderer>().material = newMat;

                firstBobble.GetComponent <SpringJoint>().spring += 100 * newBobble.GetComponent <Rigidbody>().mass;
                newLayer.Add(newBobble);
            }
        }
        bobbles.Add(newLayer);
        //Debug.Log("finnished adding next Layer");
    }
예제 #2
0
    public Tree(Tree p1, Tree p2)
    {
        //mix of parents genetics, plus mutations

        /*
         * public ArrayList layerCount; //length = num extra layers, each item gives the num braches per layer
         * public float sizeN;
         * public float sizeD;
         *
         * public Color seedCol;
         * public Color bobbleCol;
         * public int bobbleColVar;
         */


        //general variance
        generalVar = myRange(p1.generalVar, p2.generalVar);
        if (commonMute())
        {
            generalVar += UnityEngine.Random.Range(-generalVar / 10, generalVar / 10);
        }
        if (rareMute())
        {
            generalVar += UnityEngine.Random.Range(-generalVar / 2, generalVar / 2);
        }
        //sanitation
        if (generalVar >= 1 || generalVar <= 0)
        {
            generalVar = 0.5f;
        }


        //sizeN
        sizeN = myRange(p1.sizeN, p2.sizeN);
        if (commonMute())
        {
            sizeN += UnityEngine.Random.Range(-sizeN / 10, sizeN / 10);
        }
        if (rareMute())
        {
            sizeN += UnityEngine.Random.Range(-sizeN / 2, sizeN / 2);
        }
        //sizeD
        sizeD = myRange(p1.sizeD, p2.sizeD);
        if (commonMute())
        {
            sizeD += UnityEngine.Random.Range(-sizeD / 10, sizeD / 10);
        }
        if (rareMute())
        {
            sizeD += UnityEngine.Random.Range(-sizeD / 2, sizeD / 2);
        }
        ///sanitation
        if (sizeN < 1)
        {
            sizeN = 1;
        }
        if (sizeD < sizeN + 1)
        {
            sizeD = sizeN + 1;
        }

        //colors
        seedCol   = MyColors.Varient(p1.seedCol, p2.seedCol, generalVar);
        bobbleCol = MyColors.Varient(p1.bobbleCol, p2.bobbleCol, generalVar);

        bobbles    = new ArrayList {
        };
        layerCount = new ArrayList {
        };
        int i;

        for (i = 0; i < Mathf.Min(p1.layerCount.Count, p2.layerCount.Count); i++)
        {
            if (UnityEngine.Random.Range(0.0f, 1.0f) < 0.5)
            {
                layerCount.Add(p1.layerCount[i]);
            }
            else
            {
                layerCount.Add(p2.layerCount[i]);
            }
        }
        i++;
        while (heads())
        {
            if (p1.layerCount.Count > i)
            {
                layerCount.Add(p1.layerCount[i]);
            }
            else if (p2.layerCount.Count > i)
            {
                layerCount.Add(p2.layerCount[i]);
            }
            else
            {
                break;
            }
            i++;
        }


        mutateStructure();
    }