void CheckHexNextDestroyGem(GemController.Direction direction, Vector2 aroundGemPos, Color color) { Collider2D candidateNext; if (direction.Equals(GemController.Direction.UP)) { candidateNext = Physics2D.OverlapBox(new Vector2(aroundGemPos.x, aroundGemPos.y + 0.7f), new Vector2(0.5f, 0.5f), 0); CandidateNextAddDestory(candidateNext, direction, color); } else if (direction.Equals(GemController.Direction.DOWN)) { candidateNext = Physics2D.OverlapBox(new Vector2(aroundGemPos.x, aroundGemPos.y - 0.7f), new Vector2(0.5f, 0.5f), 0); CandidateNextAddDestory(candidateNext, direction, color); } else if (direction.Equals(GemController.Direction.LEFTDOWN)) { candidateNext = Physics2D.OverlapBox(new Vector2(aroundGemPos.x - 0.6f, aroundGemPos.y - 0.3f), new Vector2(0.5f, 0.5f), 0); CandidateNextAddDestory(candidateNext, direction, color); } else if (direction.Equals(GemController.Direction.LEFTUP)) { candidateNext = Physics2D.OverlapBox(new Vector2(aroundGemPos.x - 0.6f, aroundGemPos.y + 0.3f), new Vector2(0.5f, 0.5f), 0); CandidateNextAddDestory(candidateNext, direction, color); } else if (direction.Equals(GemController.Direction.RIGHTDOWN)) { candidateNext = Physics2D.OverlapBox(new Vector2(aroundGemPos.x + 0.6f, aroundGemPos.y - 0.3f), new Vector2(0, 0), 0); CandidateNextAddDestory(candidateNext, direction, color); } else if (direction.Equals(GemController.Direction.RIGHTUP)) { candidateNext = Physics2D.OverlapBox(new Vector2(aroundGemPos.x + 0.6f, aroundGemPos.y + 0.3f), new Vector2(0, 0), 0); CandidateNextAddDestory(candidateNext, direction, color); } }
void CandidateNextAddDestory(Collider2D candidateNext, GemController.Direction direction, Color color) { if (candidateNext && candidateNext.GetComponent <SpriteRenderer>().color.Equals(color)) { destroyGems.Add(candidateNext.gameObject.GetComponent <GemController>()); CheckHexNextDestroyGem(direction, candidateNext.transform.position, color); } }
void CheckHexDestroyGem(GemController.Direction direction, GemController candidatesEqualsColor) { if (direction.Equals(GemController.Direction.DOWN)) { foreach (GemController candidatesEqualsColorNext in candidatesEqualsColors) { if (candidatesEqualsColorNext._Direction.Equals(GemController.Direction.UP)) { destroyGems.Add(candidatesEqualsColorNext); destroyGems.Add(candidatesEqualsColor); } } } else if (direction.Equals(GemController.Direction.LEFTDOWN)) { foreach (GemController candidatesEqualsColorNext in candidatesEqualsColors) { if (candidatesEqualsColorNext._Direction.Equals(GemController.Direction.RIGHTUP)) { destroyGems.Add(candidatesEqualsColorNext); destroyGems.Add(candidatesEqualsColor); } } } else if (direction.Equals(GemController.Direction.LEFTUP)) { foreach (GemController candidatesEqualsColorNext in candidatesEqualsColors) { if (candidatesEqualsColorNext._Direction.Equals(GemController.Direction.RIGHTDOWN)) { destroyGems.Add(candidatesEqualsColorNext); destroyGems.Add(candidatesEqualsColor); } } } }