/// <summary> /// animates the graphics, moving it to a target ingredient /// </summary> /// <param name="target"></param> /// <returns></returns> public void MoveIngredients(Ingredient target) { ActualID = -1; ingredientsToMove = transform.GetChild(0); for (int i = 1; i < transform.childCount; i++) { transform.GetChild(i).parent = ingredientsToMove; } //ingredientsToMove.parent = null; #region Animation Setup float heightMult = ingredientsPile.Count > 1 ? target.ingredientsPile.Count : target.ingredientsPile.Count + 1; targetPosition = target.transform.position + Vector3.up * ingredientsHeight * heightMult; targetRotation = ingredientsToMove.eulerAngles; if (targetPosition.x < transform.position.x) { // 0 e 0 o !=0 e != 0 //+180z if (HeadUp && FaceUp || !HeadUp && !FaceUp) { targetRotation.z += 180f; } else { targetRotation.z -= 180f; } } else if (targetPosition.x > transform.position.x) { //-180z if (HeadUp && FaceUp || !HeadUp && !FaceUp) { targetRotation.z -= 180f; } else { targetRotation.z += 180f; } } else if (targetPosition.z < transform.position.z) { //-180x if (HeadUp && FaceUp || !HeadUp && !FaceUp) { targetRotation.x -= 180f; } else { targetRotation.x += 180f; } } else if (targetPosition.z > transform.position.z) { //+180x if (HeadUp && FaceUp || !HeadUp && !FaceUp) { targetRotation.x += 180f; } else { targetRotation.x -= 180f; } } flipSequence = DOTween.Sequence().OnComplete(() => { ingredientsToMove.parent = target.transform; for (int i = 0; i < ingredientsToMove.childCount; i++) { ingredientsToMove.GetChild(i).parent = target.transform; } target.ChooseTopIngredient(); OnAnimationComplete(); }); flipSequence.Append(ingredientsToMove.DOMove(ingredientsToMove.position + Vector3.up * (targetPosition.y + 0.2f), .3f)).SetEase(Ease.Linear); flipSequence.Append(ingredientsToMove.DOMove(targetPosition, .3f)).SetEase(Ease.OutBounce); flipSequence.Insert(0f, ingredientsToMove.DORotate(targetRotation, flipSequence.Duration())); #endregion flipSequence.Play(); }