public void Complete(IPopupUI popup) { RectTransform rectTrans = popup.GetRect(); rectTrans.localPosition = finishTransform.position; rectTrans.localRotation = finishTransform.rotation; rectTrans.localScale = finishTransform.scale; }
/// <summary> /// /// </summary> /// <param name="popup"></param> /// <param name="OnCompletedCallback">Optional callback, may be null</param> /// <returns></returns> public IEnumerator RunAnimation(IPopupUI popup, System.Action OnCompletedCallback) { RectTransform rectTrans = popup.GetRect(); Vector3 startPos = startTransform.position; Vector3 finishPos = finishTransform.position; Vector3 startScale = startTransform.scale; Vector3 finishScale = finishTransform.scale; Quaternion startRot = startTransform.rotation; Quaternion finishRot = finishTransform.rotation; float time = 0; switch (type) { case PopupAnimationType.CustomRoutine: while (time < timeToFinish) { yield return(null); time += Time.unscaledDeltaTime; float t = time / timeToFinish; animationRoutine.Invoke(t, rectTrans); } animationRoutine.Invoke(1, rectTrans); break; case PopupAnimationType.Linear: while (time < timeToFinish) { yield return(null); time += Time.unscaledDeltaTime; float t = time / timeToFinish; rectTrans.localPosition = Vector3.Lerp(startPos, finishPos, t); rectTrans.localRotation = Quaternion.Lerp(startRot, finishRot, t); rectTrans.localScale = Vector3.Lerp(startScale, finishScale, t); } rectTrans.localPosition = finishPos; rectTrans.localRotation = finishRot; rectTrans.localScale = finishScale; break; case PopupAnimationType.Quadratic: Debug.Log("not yet implemented"); yield return(null); rectTrans.localPosition = finishPos; rectTrans.localRotation = finishRot; rectTrans.localScale = finishScale; break; case PopupAnimationType.CustomCurve: while (time < timeToFinish) { yield return(null); time += Time.unscaledDeltaTime; float t = animationCurve.Evaluate(time / timeToFinish); rectTrans.localPosition = Vector3.Lerp(startPos, finishPos, t); rectTrans.localRotation = Quaternion.Lerp(startRot, finishRot, t); rectTrans.localScale = Vector3.Lerp(startScale, finishScale, t); } rectTrans.localPosition = finishPos; rectTrans.localRotation = finishRot; rectTrans.localScale = finishScale; break; } if (OnCompletedCallback != null) { OnCompletedCallback.Invoke(); } }