void Start()
 {
     iOriginalLayer = gameObject.layer;
     gameObject.layer = 8;
     tBreakableBox = gameObject.GetComponent<BreakableBox>();
     fEndTime = Time.time + Random.Range(0.1f, 0.5f);
     BoxPool.DebrisList.Add(this);
 }
    public void AddChild(BreakableBox tBox)
    {
        if (!Childs.Contains(tBox)) {
            Childs.Add(tBox);
            tBox.transform.SetParent(transform);
            m_bSimplifyCheck = true;

            int iWidth = BreakCount (bounds.size.x, BoxPool.DebrisSize);
            int iHeight = BreakCount (bounds.size.y, BoxPool.DebrisSize);
            Vector3 tTopLeft = bounds.center - bounds.extents;
            tTopLeft.x += BoxPool.DebrisSize / 2;
            tTopLeft.y += BoxPool.DebrisSize / 2;
            for (int x = 0; x < iWidth; ++x)
                for (int y = 0; y < iHeight; ++y) {
                    if (tBox.Collider.bounds.Contains (transform.localToWorldMatrix.MultiplyPoint(new Vector3 (tTopLeft.x + (x * BoxPool.DebrisSize), tTopLeft.y + (y * BoxPool.DebrisSize))))) {
                        Debug.Log (x + ", " + y);
                        StructGrid [x, y].Box = tBox;
                    }
                }
        }
    }
Esempio n. 3
0
 void AddNeighbor(List<BreakableBox> tBoxes, BreakableBox tBox)
 {
     if (tBox != null && tBox != this && !tBoxes.Contains (tBox)) {
         Debug.Log (tBox);
         tBoxes.Add (tBox);
     }
 }
 bool SimplifyChild(BreakableBox tBox)
 {
     for (int j=0; j<tBox.Neighbours.Count; ++j) {
         BreakableBox tNeighbour = tBox.Neighbours [j];
         if ((tBox.Temperature + tNeighbour.Temperature >= 0.05f) || tBox.Sprite.color != tNeighbour.Sprite.color)
             continue;
         Vector3 tP1 = tBox.transform.localPosition;
         Vector3 tP2 = tNeighbour.transform.localPosition;
         Vector3 tS1 = tBox.transform.localScale;
         Vector3 tS2 = tNeighbour.transform.localScale;
         if (Mathf.Abs(tS1.x - tS2.x) <= 0.05f && Mathf.Abs(tP1.x - tP2.x) <= 0.05f) {
             tBox.transform.localScale = new Vector3(tS1.x, tS1.y + tS2.y, 1);
             tBox.transform.localPosition = new Vector3((tP1.x + tP2.x) / 2, ((tP1.y * tS1.y) + (tP2.y * tS2.y)) / (tS1.y + tS2.y), (tP1.z + tP2.z) / 2);
             tBox.ResetNeighbours();
             tNeighbour.Deactivate();
             tBox.RefreshNeighbours();
             return true;
         }
         if (Mathf.Abs(tS1.y - tS2.y) <= 0.05f && Mathf.Abs(tP1.y - tP2.y) <= 0.05f) {
             tBox.transform.localScale = new Vector3(tS1.x + tS2.x, tS1.y, 1);
             tBox.transform.localPosition = new Vector3(((tP1.x * tS1.x) + (tP2.x * tS2.x)) / (tS1.x + tS2.x), (tP1.y + tP2.y) / 2, (tP1.z + tP2.z) / 2);
             tBox.ResetNeighbours();
             tNeighbour.Deactivate();
             tBox.RefreshNeighbours();
             return true;
         }
     }
     return false;
 }
 public void RemoveChild(BreakableBox tBox)
 {
     childs.Remove(tBox);
     int iWidth = BreakCount (bounds.size.x, BoxPool.DebrisSize);
     int iHeight = BreakCount (bounds.size.y, BoxPool.DebrisSize);
     for (int x = 0; x < iWidth; ++x)
         for (int y = 0; y < iHeight; ++y) {
             if (StructGrid [x, y].Box == tBox)
                 StructGrid [x, y].Box = null;
         }
     if (childs.Count == 0)
         Deactivate();
     else if (childs.Count > 1) {
         m_bIntegrityCheck = true;
         m_bSimplifyCheck = true;
     }
 }
 public void GetConnectedBoxes( BreakableBox tBox, List<BreakableBox> tBoxes)
 {
     if (tBoxes.Contains(tBox))
         return;
     tBoxes.Add(tBox);
     tBox.RefreshNeighbours();
     for (int i = 0; i < tBox.Neighbours.Count; i++)
         GetConnectedBoxes(tBox.Neighbours [i], tBoxes);
 }
 public void DetachBox(BreakableBox tBox)
 {
     WaitForUpdate();
     var tList = new List<BreakableBox>();
     tList.Add(tBox);
     DetachBody(tList);
 }