Advertisement
Guest User

Untitled

a guest
May 26th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 KB | None | 0 0
  1.  private IEnumerator routineRollCube() {
  2.         float rotateAmount = 90.0f;
  3.         Vector3 delta = new Vector3(rotateAmount, 0f, 0f);
  4.         Vector3 axis = Vector3.left;
  5.         Vector3 currentPivot = _pivotList[_pivotIndex].transform.position;
  6.  
  7.         float initialDuration = _gameManager.RollDuration;
  8.         float warpedDuration = _gameManager.RollDuration;
  9.  
  10.         var reachedHalfPoint = false;
  11.         var isOnTile = true;
  12.  
  13.         float startTime = Time.time;
  14.         float endTime = startTime + warpedDuration;
  15.  
  16.         float oldY = colliderGo.transform.position.y;
  17.  
  18.         Vector3 translateVector = new Vector3(0, 0, 0);
  19.  
  20.         Quaternion rotationFinish = modelGo.transform.rotation * Quaternion.Euler(new Vector3(-rotateAmount, 0f,0f));
  21.         Vector3 positionFinish = modelGo.transform.position;
  22.         positionFinish.z -= 1f;
  23.  
  24.         desolidifyIfWaterCube();
  25.  
  26.         _rollPercentage = 0f;
  27.  
  28.         while (true) {
  29.             while (_gameManager.isPaused) {
  30.                 yield return null;
  31.             }
  32.  
  33.            
  34.             warpedDuration += (initialDuration) - (warpedDuration * 0.5f); // todo; pull from time warp
  35.  
  36.             _rollPercentage = (Time.time - startTime) / warpedDuration;
  37.             if (_rollPercentage > 1f) {
  38.                 break;
  39.             }
  40.  
  41.             float angle = rotateAmount * (Time.deltaTime / warpedDuration);
  42.  
  43.             // Check to see if cube is out of bounds, or current tile is no longer active
  44.             if (currentTile == null || !currentTile.isInPlay) {
  45.                 fallIfNeeded();
  46.                 IsBusy = false;
  47.                 yield break;
  48.             }
  49.  
  50.             isOnTile = _gameManager.TileHasNextTile(currentTile);
  51.             if (!isOnTile) {
  52.                 //Debug.Log("is not on tile");
  53.             }
  54.  
  55.             // Check to see if cube was removed
  56.             if (!mIsInActiveCubes) {
  57.                 IsBusy = false;
  58.                 yield break;
  59.             }
  60.  
  61.             // Move cube to next tile if at half point
  62.             if (!reachedHalfPoint && _rollPercentage >= 0.5f) {
  63.                 // If next tile does not exist, then trigger a fall
  64.                 if (!_gameManager.TileHasNextTile(currentTile)) {
  65.                     fallIfNeeded();
  66.                     IsBusy = false;
  67.                     yield break;
  68.                 }
  69.                 _gameManager.AddMoveCubeToTile(GameBoard.Direction.DOWN, currentTile);
  70.                 reachedHalfPoint = true;
  71.             }
  72.  
  73.             modelGo.transform.RotateAround(currentPivot, axis, angle);
  74.  
  75.             // Translation
  76.             translateVector = modelGo.transform.position;
  77.             translateVector.y = oldY;
  78.            
  79.             colliderGo.transform.position = translateVector;
  80.  
  81.             yield return null;
  82.         }
  83.  
  84.         _rollPercentage = -1f;
  85.  
  86.         _isRolling = false;
  87.         _gameManager.OnCubeFinishedRolling(this);
  88.         //Debug.Log("cube.isActivelyRolling = false");
  89.  
  90.         modelGo.transform.rotation = rotationFinish;
  91.         modelGo.transform.position = positionFinish;
  92.  
  93.         _pivotIndex = getNextPivotIndex();
  94.  
  95.         // Check to see if cube is out of bounds
  96.         if (currentTile == null) {
  97.             fallIfNeeded();
  98.         } else {
  99.             IsBusy = false;
  100.         }
  101.  
  102.         yield break;
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement