//动画结束后调用该方法,该方法回调uiPropList的Callback private void FinishWork() { //if (isCallBack) //{ //} propAnimationControllerState = PropAnimationControllerState.NotPlaying; SetSelf(); if (isCallBack) { callBackMessenger.CallBack(callBackEvent); isCallBack = false; } }
public int AddTask(AnimationTaskContent theTaskContent) { if (propAnimationControllerState == PropAnimationControllerState.NotPlaying) { propAnimationControllerState = PropAnimationControllerState.PlayingStart; thePropSpriteRenderer.sprite = theTaskContent.thePropSprite; startPosition = theTaskContent.startPosition; StartCoroutine(PlayGetPropAnimation()); } else { return(-1); } return(0); }
//实现动画插值的协程 IEnumerator PlayGetPropAnimation() { float startT = 0.7f; float endT = 0.4f; //k1*nt^3+k2*nt^2,满足f(nt=0)=0,f(nt=1)=1,f'(nt=0)=0,f'(nt=1)=0, float interpK1 = -2f; float interpK2 = 3f; //-k*nt^4+k*nt^2,满足f(nt=0)=0,f(nt=1)=0,用于添加视觉上的扰动项 float disturbanceK = 0.35f; Vector2 deltaPosition; Vector2 deltaScale; Vector2 disturbancePos = new Vector2(0, 4); Color deltaColora; SetSelf(); thePropTransform.position = startPosition; thePropTransform.localScale = startScale; thePropSpriteRenderer.color = startColora; deltaPosition = midPosition - startPosition; deltaScale = midScale - startScale; deltaColora = midColora - startColora; float normalize_t; float interp_normalize_k; float disturbance_normalize_k; for (float timer = 0; timer < startT; timer += Time.deltaTime) { normalize_t = timer / startT; interp_normalize_k = interpK1 * normalize_t * normalize_t * normalize_t + interpK2 * normalize_t * normalize_t; disturbance_normalize_k = -disturbanceK * normalize_t * normalize_t * normalize_t * normalize_t + disturbanceK * normalize_t * normalize_t; thePropTransform.position = startPosition + deltaPosition * interp_normalize_k + disturbancePos * disturbance_normalize_k; thePropTransform.localScale = startScale + deltaScale * interp_normalize_k; thePropSpriteRenderer.color = startColora + deltaColora * interp_normalize_k; if (Input.GetMouseButtonDown(0)) { break; } yield return(0); } propAnimationControllerState = PropAnimationControllerState.MidWaitClick; thePropTransform.position = midPosition; thePropTransform.localScale = midScale; thePropSpriteRenderer.color = midColora; while (true) { if (Input.GetMouseButtonDown(0)) { //yield return 0; break; } yield return(0); } yield return(0); propAnimationControllerState = PropAnimationControllerState.PlayingEnd; deltaPosition = endPosition - midPosition; deltaScale = endScale - midScale; deltaColora = endColora - midColora; for (float timer = 0; timer < endT; timer += Time.deltaTime) { normalize_t = timer / endT; interp_normalize_k = interpK1 * normalize_t * normalize_t * normalize_t + interpK2 * normalize_t * normalize_t; disturbance_normalize_k = -disturbanceK * normalize_t * normalize_t * normalize_t * normalize_t + disturbanceK * normalize_t * normalize_t; thePropTransform.position = midPosition + deltaPosition * interp_normalize_k + disturbancePos * disturbance_normalize_k; thePropTransform.localScale = midScale + deltaScale * interp_normalize_k; thePropSpriteRenderer.color = midColora + deltaColora * interp_normalize_k; /* * if (Input.GetMouseButtonDown(0)) * { * break; * } * * */ yield return(0); } thePropTransform.position = endPosition; thePropTransform.localScale = endScale; thePropSpriteRenderer.color = endColora; yield return(0); FinishWork(); }