protected override bool Check() { var go = UITestUtils.FindEnabledGameObjectByPath(path); if (go) { var animation = go.GetComponent <Animation>(); if (animation) { if (animation.IsPlaying(animationName)) { return(true); } else { debug = 3; } } else { debug = 2; } } else { debug = 1; } return(false); }
public static IEnumerator AnimationCompleted(string path, string animationName, float timeout = 10, bool ignoreTimeScale = false) { float currentTime = Time.time; yield return(AsyncWait.StartWaitingForUnityAnimation(path, animationName, timeout)); float restTime = timeout - (Time.time - currentTime); yield return(WaitFor(() => { var go = UITestUtils.FindEnabledGameObjectByPath(path); if (go == null) { return new WaitFailed("WaitingForUnityAnimationCompleted: Object not found"); } var animation = go.GetComponent <Animation>(); if (animation != null) { if (animation.IsPlaying(animationName)) { return new WaitFailed("WaitingForUnityAnimationCompleted: Animation is played"); } else { return new WaitSuccess(); } } else { return new WaitFailed("WaitingForUnityAnimationCompleted: Animator not found"); } }, restTime, ignoreTimeScale: ignoreTimeScale)); }
public static IEnumerator ScrollToPosition(string path, float horizontalPosition, float verticalPosition, float animationDuration = 1f, float timeout = 2f, bool ignoreTimeScale = false) { var go = UITestUtils.FindEnabledGameObjectByPath(path); ScrollRect scrollRect = null; yield return(Wait.WaitFor(() => { scrollRect = go.GetComponentInParent <ScrollRect>(); if (scrollRect != null) { return new WaitSuccess(); } return new WaitFailed("can't find scroll rect durin timeout for object: " + path); }, timeout, ignoreTimeScale: ignoreTimeScale)); var currentTime = 0f; var currentPos = scrollRect.normalizedPosition; var newPos = new Vector2(horizontalPosition, verticalPosition); while (currentTime < animationDuration) { var targetPos = Vector2.Lerp(currentPos, newPos, currentTime / animationDuration); scrollRect.normalizedPosition = targetPos; currentTime += Time.deltaTime; yield return(null); } scrollRect.normalizedPosition = newPos; }
public static IEnumerator AnimatorStateStarted(string path, string stateName, float timeout, bool ignoreTimeScale = false) { var stateNames = stateName.Split(';'); var obj = UITestUtils.FindEnabledGameObjectByPath(path); if (obj == null || !obj.activeInHierarchy) { yield return(Wait.ObjectEnabled(path, timeout)); } var animator = UITestUtils.FindEnabledGameObjectByPath(path).GetComponent <Animator>(); if (GetCurrentStateName == null) { GetCurrentStateName = BuildFastOpenMemberDelegate <Animator, int, string>("GetCurrentStateName"); } yield return(Wait.WaitFor(() => { if (animator.enabled) { for (int i = 0; i < animator.layerCount; i++) { var name = GetCurrentStateName(animator, i); if (stateNames.Any(x => name.EndsWith(x))) { return new WaitSuccess(); } } } return new WaitFailed("AnimatorStateStarted failed for path: " + path + " and state name: " + stateName); }, timeout, ignoreTimeScale: ignoreTimeScale)); }
private static void Click(string path) { GameObject go = UITestUtils.FindEnabledGameObjectByPath(path); if (go == null) { Assert.Fail("Trying to click to " + path + " but it doesn't exist"); } Click(go); }
public static IEnumerator ObjectEnabled(string path, float timeout = 5, bool ignoreTimeScale = false) { yield return(WaitFor(() => { var obj = UITestUtils.FindEnabledGameObjectByPath(path); if (obj != null && obj.activeInHierarchy) { return new WaitSuccess(); } return new WaitFailed("WaitObjectEnabled path: " + path); }, timeout, ignoreTimeScale: ignoreTimeScale)); }
public static IEnumerator DragPercents(string path, float fromPercentX, float fromPercentY, float toPercentX, float toPercentY, float time = 1) { var go = UITestUtils.FindEnabledGameObjectByPath(path); var anyCamera = GameObject.FindObjectOfType <Camera>(); yield return(DragPixels(go, new Vector2(anyCamera.pixelWidth * fromPercentX, anyCamera.pixelHeight * fromPercentY), new Vector2(anyCamera.pixelWidth * toPercentX, anyCamera.pixelHeight * toPercentY), time)); }
protected override bool Check() { var go = UITestUtils.FindEnabledGameObjectByPath(path); var image = UITestUtils.FindGameObjectWithComponentInParents <Image>(go); var sr = UITestUtils.FindGameObjectWithComponentInParents <SpriteRenderer>(go); if (image != null) { if (image.mainTexture == null) { reason = "SourceImage: Image " + UITestUtils.GetGameObjectFullPath(go) + " has no texture."; return(false); } if (image.mainTexture.name != sourceName) { reason = "SourceImage: Image " + UITestUtils.GetGameObjectFullPath(go) + " has texture: " + image.mainTexture.name + " - but expected: " + sourceName; return(false); } return(true); } if (sr != null) { if (sr.sprite == null) { reason = "SourceImage: SpriteRenderer " + UITestUtils.GetGameObjectFullPath(go) + " has no sprite."; return(false); } if (sr.sprite.name != sourceName) { reason = "SourceImage: SpriteRenderer " + UITestUtils.GetGameObjectFullPath(go) + " has sprite: " + sr.sprite.name + " - but expected: " + sourceName; return(false); } return(true); } reason = "SourceImage: Game object " + UITestUtils.GetGameObjectFullPath(go) + " has no Image and SpriteRenderer component."; return(false); }
public static IEnumerator ObjectEnabledInstantiatedAndDelay(string path, float delay = 1, float timeout = 5, bool dontFail = true, bool ignoreTimeScale = false) { yield return(WaitFor(() => { var obj = UITestUtils.FindEnabledGameObjectByPath(path); //finds only enabled gameobjects if (obj != null && obj.activeInHierarchy) { return new WaitSuccess(); } return new WaitFailed("WaitObjectEnabled path: " + path); }, timeout, dontFail, ignoreTimeScale: ignoreTimeScale)); yield return(new WaitForSeconds(delay)); }
public static IEnumerator ButtonInteractible(string path, float timeout = 2f, bool dontFail = false, bool ignoreTimeScale = false) { yield return(WaitFor(() => { var go = UITestUtils.FindEnabledGameObjectByPath(path); //finds only enabled gameobjects if (go && go.activeInHierarchy) { string overlay = IsOverlayed(go); if (overlay != null) { return new WaitFailed("gameobject object " + path + " isOverlayed by " + overlay); } if (IsClickable(go)) { return new WaitSuccess(); } return new WaitFailed("gameobject " + path + " button is not interactable"); } return new WaitFailed("gameobject " + path + " is not " + (go == null ? "present on scene":"active in hierarchy")); }, timeout, dontFail, ignoreTimeScale: ignoreTimeScale)); }