IEnumerator DoUpdate(Vector3 center, Vector2 size, AnimationDoneCallBack callback, float animateTime) { Vector2[] scope = Vector2DUtils.GetScreenScope(); //to radius size = size * 0.5f; Vector3 lStart = new Vector3(scope[0].x - lr.bounds.size.x * 0.5f, center.y, center.z); Vector3 lEnd = lStart; lEnd.x = center.x - size.x - lr.bounds.size.x * 0.5f; Vector3 tStart = new Vector3(center.x, scope[1].y + tr.bounds.size.y * 0.5f, center.z); Vector3 tEnd = tStart; tEnd.y = center.y + size.y + tr.bounds.size.y * 0.5f; Vector3 rStart = new Vector3(scope[1].x + rr.bounds.size.x * 0.5f, center.y, center.z); Vector3 rEnd = rStart; rEnd.x = center.x + size.x + rr.bounds.size.x * 0.5f; Vector3 bStart = new Vector3(center.x, scope[0].y - br.bounds.size.y * 0.5f, center.z); Vector3 bEnd = bStart; bEnd.y = center.y - size.y - br.bounds.size.y * 0.5f; lr.transform.position = lStart; tr.transform.position = tStart; rr.transform.position = rStart; br.transform.position = bStart; if (Math.Abs(animateTime) > Mathf.Epsilon) { float lSpeed = ((lEnd - lStart) / animateTime).magnitude; float tSpeed = ((tEnd - tStart) / animateTime).magnitude; float rSpeed = ((rEnd - rStart) / animateTime).magnitude; float bSpeed = ((bEnd - bStart) / animateTime).magnitude; float timeUsed = 0; while (timeUsed < animateTime) { if (!pausing) { timeUsed += Time.deltaTime; Vector2DUtils.MoveToSmoothly(lr.transform, lEnd, lSpeed); Vector2DUtils.MoveToSmoothly(tr.transform, tEnd, tSpeed); Vector2DUtils.MoveToSmoothly(rr.transform, rEnd, rSpeed); Vector2DUtils.MoveToSmoothly(br.transform, bEnd, bSpeed); } yield return(null); } } lr.transform.position = lEnd; tr.transform.position = tEnd; rr.transform.position = rEnd; br.transform.position = bEnd; callback(center, size); }
void CancelPanelAnimations() { // animationDone = true; animationDoneCallBack = null; if (ongoingAnim != null) { StopCoroutine(ongoingAnim); } }
public void ShowHurt(float alpha) { if (hurtEvent != null) { StopCoroutine(hurtEvent); animationDoneCallBack = null; } hurtEvent = Hurt(alpha); StartCoroutine(hurtEvent); }
public void StartMask(Vector3 center, Vector2 size, AnimationDoneCallBack callback, float animateTime = 0f, float alpha = 0.2f) { InitSelf(); if (null != cor) { StopCoroutine(cor); } Color c = Color.black; c.a = alpha; lr.color = c; tr.color = c; rr.color = c; br.color = c; cor = StartCoroutine(DoUpdate(center, size, callback, animateTime)); }
void panelAnimations() { realDeltaTime = Mathf.Min(0.1f, Time.realtimeSinceStartup - lastTimeSinceStart); bool stageDone = true; for (int i = 0; i < bgCircles.Length; i++) { RectTransform c = bgCircles [i]; if (Mathf.Abs(c.localScale.magnitude - bgCircleScales [i].magnitude) > approximateEpsilon) { stageDone = false; // If lerping+realDeltaTime still not working, these two lines are plan C // Vector3 velocity = Vector3.zero; // c.localScale = Vector3.SmoothDamp (c.localScale, bgCircleScales [i], ref velocity, circleAnimationLerp, Mathf.Infinity, realDeltaTime); c.localScale = Vector3.Lerp(c.localScale, bgCircleScales [i], circleAnimationLerp + 6 * realDeltaTime); } } if (Mathf.Abs(m_contentAlpha.alpha - contentAlpha) > approximateEpsilon) { stageDone = false; m_contentAlpha.alpha = Mathf.Lerp(m_contentAlpha.alpha, contentAlpha, contentAnimationLerp + 6 * realDeltaTime); } if (Mathf.Abs(m_deadTextt.color.a - deadAlpha) > approximateEpsilon) { // stageDone = false; Color rgba = m_deadTextt.color; rgba.a = Mathf.Lerp(rgba.a, deadAlpha, deadTextAnimationLerp + 6 * realDeltaTime); m_deadTextt.color = rgba; } animationDone = stageDone; if (animationDone && animationDoneCallBack != null) { animationDoneCallBack(); animationDoneCallBack = null; } }