示例#1
0
    void Split()
    {
        if (GameObject.FindGameObjectsWithTag("Cell").Length > 1000)
        {
            return;
        }

        GameObject child1 = Instantiate(PrefabSupplier.CellPrefabReference, transform.position, transform.rotation, transform.parent);
        GameObject child2 = Instantiate(PrefabSupplier.CellPrefabReference, transform.position, transform.rotation, transform.parent);

        child1.transform.rotation *= Quaternion.Euler(0, 0, genome[CellModeIndex].SplitAngle + genome[CellModeIndex].Child1Angle);
        child2.transform.rotation *= Quaternion.Euler(0, 0, genome[CellModeIndex].SplitAngle + genome[CellModeIndex].Child2Angle);
        Rigidbody2D child1physics = child1.GetComponent <Rigidbody2D>();
        Rigidbody2D child2physics = child2.GetComponent <Rigidbody2D>();
        Cell        child1Data    = child1.GetComponent <Cell>();
        Cell        child2Data    = child2.GetComponent <Cell>();

        child1Data.Mass          = Mass / 2f;
        child2Data.Mass          = Mass / 2f;
        child1Data.genome        = genome.Clone();
        child2Data.genome        = genome.Clone();
        child1Data.CellModeIndex = genome[CellModeIndex].Child1ModeIndex;
        child2Data.CellModeIndex = genome[CellModeIndex].Child2ModeIndex;

        Vector2 splitVelocity = new Vector2(-.3f, 0).Rotate(transform.eulerAngles.z + genome[CellModeIndex].SplitAngle);

        child1physics.velocity = physics.velocity + splitVelocity;
        child2physics.velocity = physics.velocity - splitVelocity;

        //Component[] child1Components = child1.GetComponents<Component>();
        //Component[] child2Components = child2.GetComponents<Component>();

        if (genome[CellModeIndex].Child1KeepAdhesin)
        {
            ReBuildAdhesins(child1Data, genome[CellModeIndex].Child1Angle);
        }

        if (genome[CellModeIndex].Child2KeepAdhesin)
        {
            ReBuildAdhesins(child2Data, genome[CellModeIndex].Child2Angle);
        }

        if (genome[CellModeIndex].MakeAdhesin)
        {
            GameObject adhesin = Instantiate(PrefabSupplier.AdhesinPrefabReference);
            adhesin.transform.SetParent(gameObject.transform.parent);
            Adhesin adhesinData = adhesin.GetComponent <Adhesin>();
            adhesinData.Cell1 = child1Data;
            adhesinData.Cell2 = child2Data;
            child1Data.AddAdhesin(adhesinData);
            child2Data.AddAdhesin(adhesinData);
        }

        Alive = false;
        Destroy(gameObject);
    }
示例#2
0
 void ReBuildAdhesins(Cell child, float childAngle)
 {
     foreach (Adhesin ad in adhesins)
     {
         Cell otherCell     = (ad.Cell1 != this) ? ad.Cell1 : ad.Cell2;
         bool alreadyexists = false;
         foreach (Adhesin child2Adhesin in child.adhesins)
         {
             if (child2Adhesin.Cell1 == otherCell || child2Adhesin.Cell2 == otherCell)
             {
                 alreadyexists = true;
                 break;
             }
         }
         if (!alreadyexists)
         {
             GameObject adhesin = Instantiate(PrefabSupplier.AdhesinPrefabReference);
             adhesin.transform.SetParent(gameObject.transform.parent);
             Adhesin adhesinData = adhesin.GetComponent <Adhesin>();
             adhesinData.Cell1 = child;
             adhesinData.Cell2 = otherCell;
             if (ad.Cell1 == this)
             {
                 adhesinData.Cell1AnchorPoint = ad.Cell1AnchorPoint.Rotate(-genome[CellModeIndex].SplitAngle - childAngle);
                 adhesinData.Cell2AnchorPoint = ad.Cell2AnchorPoint;
             }
             else
             {
                 adhesinData.Cell1AnchorPoint = ad.Cell2AnchorPoint.Rotate(-genome[CellModeIndex].SplitAngle - childAngle);
                 adhesinData.Cell1AnchorPoint = ad.Cell1AnchorPoint;
             }
             child.AddAdhesin(adhesinData);
             otherCell.AddAdhesin(adhesinData);
         }
     }
 }
示例#3
0
 public void AddAdhesin(Adhesin adhesin)
 {
     adhesins.Add(adhesin);
 }
示例#4
0
 internal void RemoveAdhesin(Adhesin adhesin)
 {
     adhesins.Remove(adhesin);
 }