コード例 #1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && ActiveCount > 1)
     {
         Bactery2D[] activeBacteries = GetActiveBacteries();
         Bactery2D   bactery         = activeBacteries [Random.Range(0, activeBacteries.Length)];
         bactery.StickToWall();
     }
 }
コード例 #2
0
    public float GetAverageLengthExcept()
    {
        float distanceSum = 0;

        for (int i = 0; i < bacteries.Count; i++)
        {
            Bactery2D b = bacteries [i].GetComponent <Bactery2D> ();
            if (b.props.bacteryState == BacteryState.normal)
            {
                distanceSum += Vector3.Distance(baryCenter.position, bacteries [i].transform.position);
            }
        }
        return(distanceSum / ActiveCount);
    }
コード例 #3
0
    public Bactery2D[] GetActiveBacteries()
    {
        List <Bactery2D> activeBacteries = new List <Bactery2D> ();

        for (int i = 0; i < bacteries.Count; i++)
        {
            Bactery2D b = bacteries [i].GetComponent <Bactery2D> ();
            if (b.props.bacteryState == BacteryState.normal)
            {
                activeBacteries.Add(b);
            }
        }
        return(activeBacteries.ToArray());
    }
コード例 #4
0
ファイル: Bactery2D.cs プロジェクト: TPE-team/Bacterios
    public void TestAndDivide(float number, BacteryColony2D colony, GameObject animation)
    {
        Transform colonyTransform = colony.GetComponent <Transform> ();

        if (number <= props.divisionFrequency / 60f)
        {
            GameObject newBactery = Divide(colonyTransform, animation);
            Bactery2D  newB       = newBactery.GetComponent <Bactery2D> ();
            newB.props = props.Clone();
            newB.UpdateProps();
            colony.Add(newBactery);
            UpdateBacteryCount();
        }
    }
コード例 #5
0
    void FixedUpdate()
    {
        //Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        Vector3 newBaryCenter = new Vector3();

        for (int i = 0; i < bacteries.Count; i++)
        {
            Bactery2D b = bacteries [i].GetComponent <Bactery2D> ();
            if (b.props.bacteryState == BacteryState.normal)
            {
                newBaryCenter += bacteries [i].transform.position;
                //RaycastHit insideHit;
                //if (Physics.Raycast (ray, out insideHit, 10f, insideMask)) {
                //	Debug.DrawRay (insideHit.point, insideHit.normal, Color.white);
                //	RaycastHit outsideHit;
                //	if (Physics.Raycast (ray, out outsideHit, 10f, outsideMask)) {
                //		Debug.DrawRay (outsideHit.point, outsideHit.normal, Color.yellow);
                //		Vector3 wanted_position = (insideHit.point + outsideHit.point) / 2;
                Vector3 mousePos = Input.mousePosition;
                mousePos.z = distanceToCam;
                mousePos   = Camera.main.ScreenToWorldPoint(mousePos);
                Vector3     direction        = mousePos - bacteries [i].transform.position;
                Rigidbody2D bacteryRigidBody = bacteries [i].GetComponent <Rigidbody2D> ();
                bacteryRigidBody.AddForce(direction);
                if (ActiveCount < maxBacteryCount)
                {
                    Bactery2D bactery = bacteries [i].GetComponent <Bactery2D> ();
                    bactery.TestAndDivide(Random.Range(0f, 1f), this, bacterySpawnPrefab);
                }
            }
        }
        baryCenter.position = newBaryCenter / ActiveCount;
        //Quaternion rotation = baryCenter.rotation;
        //rotation.y += Input.GetAxis ("Vertical");
        //baryCenter.rotation = rotation;
        //int mask = 1 << 10;
        //mask = ~mask;
        //RaycastHit insideHitBary;
        //if (Physics.Raycast (baryCenter.position, Camera.main.transform.forward, out insideHitBary, 100f, mask)) {
        //Debug.DrawRay (insideHit.point, insideHit.normal, Color.white);
        //	RaycastHit outsideHitBary;
        //		if (Physics.Raycast (baryCenter.position, Camera.main.transform.forward, out outsideHitBary, 100f, mask)) {
        //Debug.DrawRay (outsideHit.point, outsideHit.normal, Color.yellow);
        //		Vector3 medianPoint = (insideHitBary.point + outsideHitBary.point) / 2;
        //		Vector3 newBaryCenterPos = new Vector3 (baryCenter.position.x, medianPoint.y, medianPoint.z);
        //		baryCenter.position = newBaryCenterPos;
        //	}
        //}
    }
コード例 #6
0
    int FindClosestBacteryIndex(BacteryColony2D colony)
    {
        float minDistance = float.MaxValue;
        int   index       = -1;

        for (int i = 0; i < colony.Bacteries.Count; i++)
        {
            Bactery2D b = colony.Bacteries [i].GetComponent <Bactery2D> ();
            float     d = Vector3.Distance(colony.Bacteries [i].transform.position, transform.position);
            if (d < minDistance && b.props.bacteryState == BacteryState.normal)
            {
                minDistance = d;
                index       = i;
            }
        }
        return(index);
    }
コード例 #7
0
    public void Conjugate(int index, Vector3 targetPosition, BacteryProperties newBacteryProps)
    {
        Bactery2D b = bacteries [index].GetComponent <Bactery2D> ();

        b.StartConjugate(targetPosition, newBacteryProps);
    }