private IEnumerator Resize(Vector2 startSize, Vector2 targetSize, float duration, ResizeStyle resizeStyle) { isResizing = true; //DebugLogger.Log("Resize " + gameObject.name + " start: t=" + Time.realtimeSinceStartup); switch (resizeStyle) { case ResizeStyle.Simultaneous: currentHorizontalResize = ResizeAxis(RectTransform.Axis.Horizontal, startSize.x, targetSize.x, duration); currentVerticalResize = ResizeAxis(RectTransform.Axis.Vertical, startSize.y, targetSize.y, duration); StartCoroutine(currentHorizontalResize); yield return(StartCoroutine(currentVerticalResize)); break; case ResizeStyle.WidthFirst: currentHorizontalResize = ResizeAxis(RectTransform.Axis.Horizontal, startSize.x, targetSize.x, duration * 0.5f); currentVerticalResize = ResizeAxis(RectTransform.Axis.Vertical, startSize.y, targetSize.y, duration * 0.5f); yield return(StartCoroutine(currentHorizontalResize)); yield return(StartCoroutine(currentVerticalResize)); break; case ResizeStyle.HeightFirst: currentHorizontalResize = ResizeAxis(RectTransform.Axis.Horizontal, startSize.x, targetSize.x, duration * 0.5f); currentVerticalResize = ResizeAxis(RectTransform.Axis.Vertical, startSize.y, targetSize.y, duration * 0.5f); yield return(StartCoroutine(currentVerticalResize)); yield return(StartCoroutine(currentHorizontalResize)); break; default: break; } //DebugLogger.Log("Resize " + gameObject.name + " complete: t=" + Time.realtimeSinceStartup); isResizing = false; //float elapsedTime = 0.0f; //while (elapsedTime < duration) //{ // float percentComplete = elapsedTime / duration; // float newWidth = Mathf.Lerp(startSize.x, targetSize.x, percentComplete); // float newHeight = Mathf.Lerp(startSize.y, targetSize.y, percentComplete); // rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, newWidth); // rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, newHeight); // yield return null; // elapsedTime += Time.deltaTime; //} //rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, targetSize.x); //rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, targetSize.y); }
private IEnumerator Resize(Vector2 startSize, Vector2 targetSize, float duration, ResizeStyle resizeStyle) { isResizing = true; //DebugLogger.Log("Resize " + gameObject.name + " start: t=" + Time.realtimeSinceStartup); switch (resizeStyle) { case ResizeStyle.Simultaneous: currentHorizontalResize = ResizeAxis(RectTransform.Axis.Horizontal, startSize.x, targetSize.x, duration); currentVerticalResize = ResizeAxis(RectTransform.Axis.Vertical, startSize.y, targetSize.y, duration); StartCoroutine(currentHorizontalResize); yield return StartCoroutine(currentVerticalResize); break; case ResizeStyle.WidthFirst: currentHorizontalResize = ResizeAxis(RectTransform.Axis.Horizontal, startSize.x, targetSize.x, duration * 0.5f); currentVerticalResize = ResizeAxis(RectTransform.Axis.Vertical, startSize.y, targetSize.y, duration * 0.5f); yield return StartCoroutine(currentHorizontalResize); yield return StartCoroutine(currentVerticalResize); break; case ResizeStyle.HeightFirst: currentHorizontalResize = ResizeAxis(RectTransform.Axis.Horizontal, startSize.x, targetSize.x, duration * 0.5f); currentVerticalResize = ResizeAxis(RectTransform.Axis.Vertical, startSize.y, targetSize.y, duration * 0.5f); yield return StartCoroutine(currentVerticalResize); yield return StartCoroutine(currentHorizontalResize); break; default: break; } //DebugLogger.Log("Resize " + gameObject.name + " complete: t=" + Time.realtimeSinceStartup); isResizing = false; //float elapsedTime = 0.0f; //while (elapsedTime < duration) //{ // float percentComplete = elapsedTime / duration; // float newWidth = Mathf.Lerp(startSize.x, targetSize.x, percentComplete); // float newHeight = Mathf.Lerp(startSize.y, targetSize.y, percentComplete); // rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, newWidth); // rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, newHeight); // yield return null; // elapsedTime += Time.deltaTime; //} //rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, targetSize.x); //rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, targetSize.y); }