private IEnumerator MoveInPlaceImpl(MechanicAnimObject mechanicView, TempMechanicInfo info) { yield return(new WaitForSeconds(.2f)); Vector3Animator scaleAnimator = mechanicView.gameObject.GetOrAdd <Vector3Animator>(); Vector2Animator positionAnimator = mechanicView.gameObject.GetOrAdd <Vector2Animator>(); FloatAnimator rotateAnimator = mechanicView.gameObject.GetOrAdd <FloatAnimator>(); RectTransform rectTransform = mechanicView.GetComponent <RectTransform>(); Vector2 startPosition = rectTransform.anchoredPosition; Vector2 endPosition = mechanicView.leftPosition; Vector2AnimationData positionData = new Vector2AnimationData { StartValue = startPosition, EndValue = endPosition, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdatePositionFunctor(), OnUpdate = rectTransform.UpdatePositionTimedFunctor(), OnEnd = rectTransform.UpdatePositionFunctor(() => { Debug.Log($"setup temp mechanic on state => {info.State}"); mechanicView.Setup(info); mechanicViews.Add(mechanicView.TempMechanic.Id, mechanicView); animatedViews.Remove(mechanicView.TempMechanic.Id); }) }; Vector3AnimationData scaleData = new Vector3AnimationData { StartValue = 2f * Vector3.one, EndValue = Vector3.one, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateScaleFunctor(), OnUpdate = rectTransform.UpdateScaleTimedFunctor(), OnEnd = rectTransform.UpdateScaleFunctor() }; FloatAnimationData rotateData = new FloatAnimationData { StartValue = rectTransform.localRotation.eulerAngles.z, EndValue = 0, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateZRotation(), OnUpdate = rectTransform.UpdateZRotationTimed(), OnEnd = rectTransform.UpdateZRotation() }; positionAnimator.StartAnimation(positionData); scaleAnimator.StartAnimation(scaleData); rotateAnimator.StartAnimation(rotateData); }
private void AnimateMechanicObject(MechanicAnimObject mechanicView, TempMechanicInfo info) { Vector3Animator scaleAnimator = mechanicView.gameObject.GetOrAdd <Vector3Animator>(); Vector2Animator positionAnimator = mechanicView.gameObject.GetOrAdd <Vector2Animator>(); ColorAnimator colorAnimator = mechanicView.gameObject.GetOrAdd <ColorAnimator>(); FloatAnimator rotateAnimator = mechanicView.gameObject.GetOrAdd <FloatAnimator>(); RectTransform rectTransform = mechanicView.GetComponent <RectTransform>(); Image image = mechanicView.GetComponent <Image>(); Vector2 endOffset = Random.insideUnitCircle.normalized * 300; if (endOffset.y < 0) { endOffset.y = -endOffset.y; } Vector2 startPosition = buyButton.GetComponent <RectTransform>().anchoredPosition; Vector2 endPosition = startPosition + endOffset; Vector2AnimationData positionData = new Vector2AnimationData { StartValue = startPosition, EndValue = endPosition, Duration = 0.3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdatePositionFunctor(), OnUpdate = rectTransform.UpdatePositionTimedFunctor(), OnEnd = rectTransform.UpdatePositionFunctor(() => { StartCoroutine(MoveInPlaceImpl(mechanicView, info)); }) }; Vector3AnimationData scaleData = new Vector3AnimationData { StartValue = Vector3.one, EndValue = 2f * Vector3.one, Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateScaleFunctor(), OnUpdate = rectTransform.UpdateScaleTimedFunctor(), OnEnd = rectTransform.UpdateScaleFunctor() }; ColorAnimationData colorData = new ColorAnimationData { StartValue = new Color(1, 1, 1, 0), EndValue = new Color(1, 1, 1, 1), Duration = .1f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = image.UpdateColorFunctor(), OnUpdate = image.UpdateColorTimedFunctor(), OnEnd = image.UpdateColorFunctor() }; FloatAnimationData rotateData = new FloatAnimationData { StartValue = 0, EndValue = Random.Range(-40, 40), Duration = .3f, EaseType = EaseType.EaseInOutQuad, Target = mechanicView.gameObject, OnStart = rectTransform.UpdateZRotation(), OnUpdate = rectTransform.UpdateZRotationTimed(), OnEnd = rectTransform.UpdateZRotation() }; positionAnimator.StartAnimation(positionData); scaleAnimator.StartAnimation(scaleData); colorAnimator.StartAnimation(colorData); rotateAnimator.StartAnimation(rotateData); }