void clickedEvent(int x, int y) { if (blockList[x, y]._State == Block.State.MOVE || blockList[x, y]._State == Block.State.MATCH_END) { return; } if (!firBlock) { preMousePos = ScreenToWorldPoint(Input.mousePosition); blockList[x, y].Select(out firBlock); } else if (!secBlock && firBlock != blockList[x, y]) { int disX = firBlock._X - x; int disY = firBlock._Y - y; if (Mathf.Abs(disX) > 1 || Mathf.Abs(disY) > 1) { firBlock.DeSelect(out firBlock); return; } blockList[x, y].Select(out secBlock); } else { if (firBlock) { firBlock.DeSelect(out firBlock); } if (secBlock) { secBlock.DeSelect(out secBlock); } } }
IEnumerator swapCoroutine() { Block a = firBlock; Block b = secBlock; if (!checkClickAble(a._X) || !checkClickAble(b._X)) //before, check able swap { a.DeSelect(out a); b.DeSelect(out b); yield break; } Vector2 firPos = a._LocalPosition; Vector2 secPos = b._LocalPosition; float startTime = Time.time; while (Time.time - startTime <= swapTime) { a._LocalPosition = Vector2.Lerp(firPos, secPos, (Time.time - startTime) / swapTime); b._LocalPosition = Vector2.Lerp(secPos, firPos, (Time.time - startTime) / swapTime); yield return(null); } a._LocalPosition = secPos; b._LocalPosition = firPos; swap(a, b); yield return(new WaitForSeconds(.1f)); bool matchedA = findMatchAtBlock(a); bool matchedB = findMatchAtBlock(b); if (!matchedA && !matchedB) // Don't Matched Block!! { startTime = Time.time; while (Time.time - startTime <= swapTime) { a._LocalPosition = Vector2.Lerp(secPos, firPos, (Time.time - startTime) / swapTime); b._LocalPosition = Vector2.Lerp(firPos, secPos, (Time.time - startTime) / swapTime); yield return(null); } a._LocalPosition = firPos; b._LocalPosition = secPos; swap(a, b); } if (!matchedA) { a.DeSelect(out a); } if (!matchedB) { b.DeSelect(out b); } if (matchList.Count != 0) { matchProcess(); } }