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 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); }