/// <summary> /// Play a dropdown animation to show the player feedback /// </summary> /// <param name="dropdownType">The type of dropdown message</param> /// <param name="displayMessage">The message to display</param> private IEnumerator PlayDropdownAnimationCoroutine(RewardMobDropdownType dropdownType, string displayMessage, int?rewardCount) { //if an animation is playing, just wait yield return(new WaitUntil(() => animationCurrentlyPlaying == false)); //declare gameobj to hold clone GameObject dropdownClone = null; int maxCharactersAllowed; //declare dropdown sizes float dropdownSizeMultiplier; float dropdownWidth; //based on the dropdown type, set certain characteristics switch (dropdownType) { case (RewardMobDropdownType.REWARD): dropdownClone = Instantiate(rewardDropdownPrefab, canvas.transform); maxCharactersAllowed = REWARD_MAX_CHARACTERS; dropdownSizeMultiplier = REWARD_DROPDOWN_SIZE_MULTIPLIER; break; case (RewardMobDropdownType.WARNING): dropdownClone = Instantiate(warningDropdownPrefab, canvas.transform); maxCharactersAllowed = WARNING_MAX_CHARACTERS; dropdownSizeMultiplier = WARNING_DROPDOWN_SIZE_MULTIPLIER; break; default: yield break; } //change scale if landscape if ((Screen.orientation == ScreenOrientation.LandscapeRight) || (Screen.orientation == ScreenOrientation.LandscapeLeft)) { dropdownClone.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); } animationCurrentlyPlaying = true; //update the text property's field if (dropdownType == RewardMobDropdownType.WARNING) { dropdownClone.GetComponentInChildren <RewardMobWarningMessage>().UpdateMessage(displayMessage); } else { dropdownClone.GetComponentInChildren <RewardMobRewardMessage>().UpdateMessage(displayMessage); dropdownClone.GetComponentInChildren <RewardMobRewardCountText>().UpdateRewardCount(rewardCount); } //determine the dropdown's width if (displayMessage.Length >= maxCharactersAllowed) { dropdownWidth = DROPDOWN_MAX_WIDTH; } else if (displayMessage.Length <= MIN_CHARACTERS) { dropdownWidth = DROPDOWN_MIN_WIDTH; } else { dropdownWidth = (DROPDOWN_MIN_WIDTH + (displayMessage.Length * dropdownSizeMultiplier)); } //set it to use proper width SetWidth(dropdownClone.GetComponent <RectTransform>(), dropdownWidth); //set position to the proper dropdown location dropdownClone.transform.position = FindObjectOfType <RewardMobDropdownLocation>().GetComponent <RectTransform>().position; //halt thread to wait for animation to be finished yield return(new WaitForSeconds(DROPDOWN_DESTRUCTION_WAIT_TIME_SECONDS)); animationCurrentlyPlaying = false; //destroy when done Destroy(dropdownClone); }
/// <summary> /// Play a dropdown animation to show the player feedback /// </summary> /// <param name="dropdownType">The type of dropdown message</param> /// <param name="displayMessage">The message to display</param> public void PlayDropdownAnimation(RewardMobDropdownType dropdownType, string displayMessage, int?rewardCount = null) { StartCoroutine(PlayDropdownAnimationCoroutine(dropdownType, displayMessage, rewardCount)); }