public void creatNewBlockGroup() { if (GameManager.Instance.GameState == GameManager.GameStates.GameOver) { return; } if (BlocksManager.Instance.LeftColors.Count == 0) { return; } currentBlockGroup = GameObjectPoolManager.Instance.Pool_BlockGroupPool.AllocateGameObject <BlockGroup>(transform); currentBlockGroup.transform.position = StartPosition; currentBlockGroup.transform.rotation = transform.rotation; currentBlockGroup.Initialize(); }
private void tryBreakIntoPieces() { if (bList.Count == 0) { return; } int[] unionFind = new int[bList.Count]; for (int i = 0; i < unionFind.Length; i++) { unionFind[i] = i; } for (int i = 0; i < bList.Count; i++) { for (int j = i + 1; j < bList.Count; j++) { if (bList[i].gridPosition[0] == bList[j].gridPosition[0]) { if (bList[i].gridPosition[1] + 1 == bList[j].gridPosition[1] || bList[i].gridPosition[1] - 1 == bList[j].gridPosition[1]) { int rootI = i; while (rootI != unionFind[rootI]) { rootI = unionFind[rootI]; } int rootJ = j; while (rootJ != unionFind[rootJ]) { rootJ = unionFind[rootJ]; } if (rootI != rootJ) { unionFind[rootJ] = rootI; } } } else if (bList[i].gridPosition[1] == bList[j].gridPosition[1]) { if (bList[i].gridPosition[0] + 1 == bList[j].gridPosition[0] || bList[i].gridPosition[0] - 1 == bList[j].gridPosition[0]) { int rootI = i; while (rootI != unionFind[rootI]) { rootI = unionFind[rootI]; } int rootJ = j; while (rootJ != unionFind[rootJ]) { rootJ = unionFind[rootJ]; } if (rootI != rootJ) { unionFind[rootJ] = rootI; } } } } } for (int i = 0; i < unionFind.Length; i++) { while (unionFind[i] != unionFind[unionFind[i]]) { unionFind[i] = unionFind[unionFind[i]]; } } Dictionary <int, List <Block> > dic = new Dictionary <int, List <Block> >(); for (int i = 0; i < unionFind.Length; i++) { if (!dic.ContainsKey(unionFind[i])) { dic.Add(unionFind[i], new List <Block>()); } dic[unionFind[i]].Add(bList[i]); } if (dic.Count == 1) { return; } foreach (List <Block> lb in dic.Values) { BlockGroup newBlockGroup = GameObjectPoolManager.Instance.Pool_BlockGroupPool.AllocateGameObject <BlockGroup>(transform.parent); newBlockGroup.transform.rotation = transform.parent.rotation; newBlockGroup.transform.position = transform.position; foreach (Block b in lb) { b.transform.parent = newBlockGroup.transform; } newBlockGroup.Initialize(lb); newBlockGroup.isPiece = true; BlocksManager.Instance.currentBlockGroupPieces.Add(newBlockGroup); } bList.Clear(); isBroken = true; if (isPiece) { BlocksManager.Instance.currentBlockGroupPieces.Remove(this); } PoolRecycle(); BlocksManager.Instance.resetKeyPressTime(); BlocksManager.Instance.resetKeyPressBeginTime(); }