public override void InitializeAgent()
 {
     jdController = GetComponent <JointDriveController>();
     // Handle starting/communication with api data
     cell = GetComponent <Cell>();
     if (requestApiData)
     {
         PostGene postGene = transform.gameObject.AddComponent <PostGene>();
         StartCoroutine(postGene.getCell(cellId));
         cell.partNb    = partNb;
         cell.threshold = threshold;
     }
     else
     {
         cell.initGerms(partNb, threshold);
     }
     currentDecisionStep = 1;
 }
Exemple #2
0
        public void initGerms(int numGerms, float threshold)
        {
            PostGene postGene = new PostGene();

            // RENAME THE PARENT GAMEOBJECT//
            //transform.gameObject.name = Utils.RandomName();
            /////////////////////////////////
            // INIT GENE LIST //
            ////////////////////
            Germs         = new List <List <GameObject> >();
            Cells         = new List <GameObject>();
            CellPositions = new List <Vector3>();

            List <Vector3> sides = new List <Vector3> {
                new Vector3(1f, 0f, 0f),
                new Vector3(0f, 1f, 0f),
                new Vector3(0f, 0f, 1f),
                new Vector3(-1f, 0f, 0f),
                new Vector3(0f, -1f, 0f),
                new Vector3(0f, 0f, -1f)
            };

            //////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////INIT BASE GERMS///////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////
            /// 1ST CELL ///
            // init object shape
            Germs.Add(new List <GameObject>());
            GameObject initCell = InitBaseShape(Germs[0], 0);

            InitRigidBody(initCell);
            HandleStoreCell(initCell);
            //////////////////////////////////////////////////////////////////////////////////////


            //////////////////////////////////////////////////////////////////////////////////////
            /////////////////// Iterate for each new part of the morphology //////////////////////
            /// //////////////////////////////////////////////////////////////////////////////////
            int x = 0;

            for (int y = 1; y < numGerms; y++)
            {
                int prevCount = Germs[y - 1].Count;
                Germs.Add(new List <GameObject>());
                //////////////////////////////////////////////////
                /// ITERATE FOR EACH PREVIOUS GERM CELL NUMBER ///
                for (int i = 0; i < prevCount; i++)
                {
                    //////////////////////////////////////////////////
                    ////////// ITERATE FOR EACH CELL SIDES ///////////
                    for (int z = 0; z < sides.Count; z++)
                    {
                        bool    isValid      = true;
                        float   CellInfo     = Random.Range(0f, 1f);
                        Vector3 cellPosition = Germs[y - 1][i].transform.position + sides[z];

                        CellInfo = HandleCellsRequest(x, CellInfo);

                        isValid = CheckIsValid(isValid, cellPosition);
                        if (isValid)
                        {
                            if (CellInfos[x] > threshold)
                            {
                                GameObject cell = InitBaseShape(Germs[y], y);
                                InitPosition(sides, y, i, z, cell);
                                InitRigidBody(cell);
                                initJoint(cell, Germs[y - 1][i], sides[z]);
                                HandleStoreCell(cell);
                            }
                        }
                        x++;
                    }
                }

                foreach (var cell in Cells)
                {
                    cell.transform.parent = transform;
                }
            }

            foreach (var cell in Cells)
            {
                cell.transform.localScale *= 2f;
                cell.GetComponent <SphereCollider>().radius /= 2f;
            }

            //////////////////////////////////////////////////////////////////////////////////////
            string postData = HandlePostData();

            AddAgentPart();

            if (postApiData)
            {
                ////Post data to Api
                //GameObject.Find("Focus Camera").GetComponent<WebCamPhotoCamera>().CaptureScreenshot();
                StartCoroutine(postGene.postCell(postData, transform.gameObject.name));
            }
        }