public void MovedLevel(float newXPos) { float screenFactor = newXPos / screenWidth; bool rightSwipe = screenFactor > 0.5f; float factorDone = rightSwipe ? (screenFactor - 0.5f) * 2 : 1 - (screenFactor * 2); Transform parent = frontTransform; allLevels[selectedLevel].SelectedParent(selectedTransform); if (newXPos >= 0 && newXPos <= screenWidth) { for (int i = 0; i < allLevels.Count; i++) { float visibility = 1; bool changeAllowed = true; if (i != selectedLevel) { int slotID = i - selectedLevel; float newPos = frontX; float newScale = frontScale; switch (slotID) { case -3: if (rightSwipe) { newPos = leftX02; newScale = scale02; visibility *= factorDone; parent = leftTransform02; } else { changeAllowed = false; } break; case -2: if (rightSwipe) { newPos = leftX01; newScale = scale01; parent = leftTransform01; } else { newPos = leftBackX; newScale = backScale; visibility *= (1 - factorDone); parent = leftTransformBack; } break; case -1: if (rightSwipe) { newPos = frontX; newScale = frontScale; parent = frontTransform; } else { newPos = leftX02; newScale = scale02; parent = leftTransform02; } break; case 1: if (rightSwipe) { newPos = rightX02; newScale = scale02; parent = rightTransform02; } else { newPos = frontX; newScale = frontScale; parent = frontTransform; } break; case 2: if (rightSwipe) { newPos = rightBackX; newScale = backScale; visibility *= (1 - factorDone); parent = rightTransformBack; } else { newPos = rightX01; newScale = scale01; parent = rightTransform01; } break; case 3: if (rightSwipe) { changeAllowed = false; } else { newPos = rightX02; newScale = scale02; visibility *= factorDone; parent = rightTransform02; } break; default: changeAllowed = false; break; } if (rightSwipe && swipeTrasform != SwipeTransform.RIGHT) { allLevels[i].SetParentDirection(parent); } else if (!rightSwipe && swipeTrasform != SwipeTransform.LEFT) { allLevels[i].SetParentDirection(parent); } if (changeAllowed) { allLevels[i].MoveToNextView(newPos, factorDone, newScale, visibility); } } } if (rightSwipe && swipeTrasform != SwipeTransform.RIGHT) { swipeTrasform = SwipeTransform.RIGHT; } else if (!rightSwipe && swipeTrasform != SwipeTransform.LEFT) { swipeTrasform = SwipeTransform.LEFT; } } }
private IEnumerator ChangePos(bool right, float xPos) { float destination = right ? screenWidth : 0; float distance = destination - xPos; float newPos = xPos; while (newPos != destination) { float movement = distance * Time.deltaTime * moveSpeed; if (Mathf.Abs(movement) > Mathf.Abs(destination - newPos)) { newPos = destination; } else { newPos += movement; } allLevels[selectedLevel].SelectedMove(newPos); MovedLevel(newPos); yield return(null); } destination = right ? screenWidth + 500 : -500; distance = destination - xPos; while (right ? newPos <destination : newPos> destination) { newPos += distance * Time.deltaTime * moveSpeed; allLevels[selectedLevel].SelectedMove(newPos); yield return(null); } int previousSelected = selectedLevel; if (right) { destination = rightX01; selectedLevel--; } else { destination = leftX01; selectedLevel++; } for (int i = 0; i < allLevels.Count; i++) { SetNewDefaults(i); } ChangeDiscription(); allLevels[previousSelected].SetParentDirection(right ? rightTransform01 : leftTransform01); swipeTrasform = SwipeTransform.NONE; distance = destination - newPos; while (newPos != destination) { // Movement float movement = distance * Time.deltaTime * moveSpeed; if (Mathf.Abs(movement) > Mathf.Abs(destination - newPos)) { newPos = destination; } else { newPos += movement; } // Scale float factorDone = 1 - (destination - newPos) / distance; float newScale = 1 + (scale01 - 1) * factorDone; allLevels[previousSelected].SelectedMove(newPos, newScale); yield return(null); } allLevels[selectedLevel].EnableSelection(); }