Ejemplo n.º 1
0
    IEnumerator DataUpdater(int update)
    {
        float totalTime = 0;

        while (true)
        {
            using (StreamWriter sw = File.CreateText(file)) {
                sw.WriteLine(update);

                sw.WriteLine(totalTime);

                yield return(new WaitForSeconds(.01f));  // just to fix a thing

                List <GameObject> organismList = OrganismObject.Search("Organism", Mathf.Infinity);
                sw.WriteLine(organismList.Count);

                List <GameObject> foodList = OrganismObject.Search("Food", Mathf.Infinity);
                sw.WriteLine(foodList.Count);
            }

            yield return(new WaitForSeconds(update));

            File.WriteAllText(file, String.Empty);
            totalTime = Time.realtimeSinceStartup;
        }
    }
Ejemplo n.º 2
0
    IEnumerator FoodSpawn(int foodAmount, float time, int capacity)
    {
        while (true)
        {
            int foodCount = OrganismObject.Search("Food", Mathf.Infinity).Count;

            if (foodCount + 500 > capacity)
            {
                foodAmount = capacity - foodCount;
            }

            for (int i = 0; i < foodAmount; i++)
            {
                Instantiate(berry, new Vector3(UnityEngine.Random.Range(-110, 110), .3f, UnityEngine.Random.Range(-110, 110)), transform.rotation);
            }

            //print($"{foodAmount} food entities have spawned.");

            yield return(new WaitForSeconds(time));
        }
    }
Ejemplo n.º 3
0
    public void AddObject()
    {
        Organism myOrganismClass = parentGameObject.GetComponent <Organism> ();

//		Vector3 previousObjectPos = myOrganismClass.gameObject.transform.position + Vector3.up * 2; //default pos is branch's base position
        Vector3 previousObjectPos = gameObject.transform.position + Vector3.up * 3;

        if (objectsData.Count > 0)
        {
            previousObjectPos = objectsData [objectsData.Count - 1].myGameObject.transform.position;
        }
        Vector3 newPosition;

        if (isCluster && myOrganismClass.objectSum < branchLength)
        {
//			Debug.Log("is cluster!");
            float   randomRange  = modelBoundSize;
            Vector3 randomOffset = new Vector3(Random.Range(-randomRange, randomRange),
                                               0,
                                               Random.Range(-randomRange, randomRange));
            newPosition = gameObject.transform.position + randomOffset + Vector3.up / 2 * myOrganismClass.objectDropingDistance + new Vector3(0, previousObjectPos.y, 0);
        }
        else
        {
            float correction = (float)-0.2 * objectMissedNumber + 1;
            if (correction < 0)
            {
                correction = 0;
            }
            newPosition = previousObjectPos + Vector3.up * myOrganismClass.objectDropingDistance + direction * correction;
        }

        GameObject      newObject            = (GameObject)Instantiate(myOrganismClass.modelGameObject, newPosition, Quaternion.identity);
        ChangeJointType changeJointTypeClass = newObject.AddComponent <ChangeJointType>();

        changeJointTypeClass.myOrganismClass = myOrganismClass;
        if (newObject.GetComponent <InfectableObject>())
        {
            Destroy(newObject.GetComponent <InfectableObject>());
//			newObject.transform.position =
        }
        modelBoundSize = newObject.GetComponent <MeshRenderer> ().bounds.extents.magnitude;

        StickyStickStuckPackage.StickyStickStuck newObjectSSS;
        if (newObject.GetComponent <StickyStickStuckPackage.StickyStickStuck>() != null)
        {
            newObjectSSS = newObject.GetComponent <StickyStickStuckPackage.StickyStickStuck> ();
        }
        else
        {
            newObjectSSS = newObject.AddComponent <StickyStickStuckPackage.StickyStickStuck> ();
        }

        Rigidbody newObjectRigidBody;

        if (newObject.GetComponent <Rigidbody>() != null)
        {
            newObjectRigidBody = newObject.GetComponent <Rigidbody> ();
        }
        else
        {
            newObjectRigidBody = newObject.AddComponent <Rigidbody> ();
        }

        newObject.GetComponent <MeshRenderer> ().enabled = false;
        newObjectRigidBody.mass        = 0.1f;
        newObjectRigidBody.drag        = 0.5f;
        newObjectRigidBody.angularDrag = 0f;
        newObjectSSS.stickProperties.stickNonRigidbodys = false;
        newObjectSSS.infectionProperties.affectInfected = true;
        newObjectSSS.stickProperties.maxStuck           = 2;
        OrganismObject myOrgan = newObject.AddComponent <OrganismObject> ();

        myOrgan.myIndex            = objectsData.Count;
        newObject.name             = "Object" + objectsData.Count;
        newObject.transform.parent = gameObject.transform;
        objectsData.Add(new ObjectData(objectsData.Count, newObject));
        myOrganismClass.objectSum++;
    }