Пример #1
0
        public List <Combine> GetCombinedObjects(GameObject[,] allObjects)
        {
            List <Combine> matchesList = new List <Combine>();

            for (int i = 0; i < allObjects.GetLength(0); i++)
            {
                for (int j = 0; j < allObjects.GetLength(1); j++)
                {
                    Combine middleCombine = allObjects[i, j].GetComponent <Combine>();
                    if (middleCombine == null)
                    {
                        continue;
                    }
                    Combine leftCombine  = middleCombine.GetNeighborCombine(Vector2Int.left, allObjects);
                    Combine rightCombine = middleCombine.GetNeighborCombine(Vector2Int.right, allObjects);
                    Combine upCombine    = middleCombine.GetNeighborCombine(Vector2Int.up, allObjects);
                    Combine downCombine  = middleCombine.GetNeighborCombine(Vector2Int.down, allObjects);

                    if (leftCombine != null && rightCombine != null)
                    {
                        if (middleCombine.Id == leftCombine.Id && middleCombine.Id == rightCombine.Id)
                        {
                            if (!matchesList.Contains(middleCombine))
                            {
                                matchesList.Add(middleCombine);
                            }
                            if (!matchesList.Contains(leftCombine))
                            {
                                matchesList.Add(leftCombine);
                            }
                            if (!matchesList.Contains(rightCombine))
                            {
                                matchesList.Add(rightCombine);
                            }
                        }
                    }
                    if (upCombine != null && downCombine != null)
                    {
                        if (middleCombine.Id == upCombine.Id && middleCombine.Id == downCombine.Id)
                        {
                            if (!matchesList.Contains(middleCombine))
                            {
                                matchesList.Add(middleCombine);
                            }
                            if (!matchesList.Contains(upCombine))
                            {
                                matchesList.Add(upCombine);
                            }
                            if (!matchesList.Contains(downCombine))
                            {
                                matchesList.Add(downCombine);
                            }
                        }
                    }
                }
            }

            return(matchesList);
        }