Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Animates a dialog when showing/hiding it
- public class DialogAnimatorSlideFromRight : DialogAnimator
- {
- // Constructor method
- public DialogAnimatorSlideFromRight(float animationDuration = 0.5f)
- {
- m_AnimationDuration = 0.5f;
- }
- // Called when the dialog is shown
- public override void AnimateShow(Action callback)
- {
- base.AnimateShow(callback);
- // Make sure that the dialog's layout is fully built before attempting to get its size
- LayoutRebuilder.ForceRebuildLayoutImmediate(m_Dialog.rectTransform);
- float halfScreenWidth = Screen.width / 2f;
- float halfDialogWidth = m_Dialog.rectTransform.GetProperSize().x / 2f;
- // Multiplied by 1.1f so the dialog is *definitely* off the screen
- float startPoint = halfScreenWidth + (halfDialogWidth * 1.1f);
- // Set the position of the dialog before animating (just past the right edge of the screen
- m_Dialog.rectTransform.anchoredPosition = new Vector2(startPoint, 0f);
- // Make the dialog full-size, now that it's not onscreen
- m_Dialog.rectTransform.localScale = Vector3.one;
- // Animate the dialog from its position to 0,0 on the screen (middle). The callback (called when the tween ends) is so the dialog knows when it's finished animating
- TweenManager.AutoTween(m_Dialog.gameObject, m_Dialog.rectTransform, "anchoredPosition", Vector2.zero, m_AnimationDuration, callback: callback);
- }
- // Called when the dialog is hidden
- public override void AnimateHide(Action callback)
- {
- base.AnimateHide(callback);
- float halfScreenWidth = Screen.width / 2f;
- float halfDialogWidth = m_Dialog.rectTransform.GetProperSize().x / 2f;
- // Multiplied by 1.1f so the dialog is *definitely* off the screen
- float endPoint = halfScreenWidth + (halfDialogWidth * 1.1f);
- TweenManager.AutoTween(m_Dialog.gameObject, m_Dialog.rectTransform, "anchoredPosition", new Vector2(endPoint, 0f), m_AnimationDuration, 0f, Tween.TweenType.EaseInCubed, callback: callback);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement