namespace UIWidgets { using System; using System.Collections; using System.Collections.Generic; using EasyLayoutNS; using UnityEngine; using UnityEngine.UI; /// /// Base class for notifications. /// public abstract class NotificationBase : MonoBehaviour, ITemplatable, IHideable { [SerializeField] bool unscaledTime; /// /// Use unscaled time. /// public bool UnscaledTime { get { return unscaledTime; } protected set { unscaledTime = value; } } bool isTemplate = true; /// /// Gets a value indicating whether this instance is template. /// /// true if this instance is template; otherwise, false. public bool IsTemplate { get { return isTemplate; } set { isTemplate = value; } } /// /// Template name. /// protected string NotificationTemplateName; /// /// Gets the name of the template. /// /// The name of the template. public virtual string TemplateName { get { return NotificationTemplateName; } set { NotificationTemplateName = value; } } /// /// Time between previous notification was hidden and next will be showed. /// public float SequenceDelay; /// /// The notification manager. /// static NotifySequenceManager notificationManager; /// /// Gets the notification manager. /// /// The notification manager. public static NotifySequenceManager NotifyManager { get { if (notificationManager == null) { var go = new GameObject("NotificationSequenceManager"); notificationManager = go.AddComponent(); } return notificationManager; } } /// /// Return this instance to cache. /// public abstract void Return(); /// /// Display notification. /// /// On hide callback. public abstract void Display(Action onHideCallback = null); /// /// Replacements cache. /// protected static readonly Stack Replacements = new Stack(); /// /// Get replacement for this instance. /// /// Replacement. protected static RectTransform GetReplacement() { RectTransform rect; if (Replacements.Count == 0) { var obj = new GameObject("NotificationReplacement"); obj.SetActive(false); rect = obj.AddComponent(); // change size don't work without graphic component var image = obj.AddComponent(); image.color = Color.clear; } else { do { rect = (Replacements.Count > 0) ? Replacements.Pop() : GetReplacement(); } while (rect == null); } return rect; } /// /// Get notification replacement. /// /// Notification instance. /// Replacement. protected static RectTransform GetReplacement(NotificationBase notification) { var target = GetReplacement(); var source_rect = notification.transform as RectTransform; target.localRotation = source_rect.localRotation; target.localPosition = source_rect.localPosition; target.localScale = source_rect.localScale; target.anchorMin = source_rect.anchorMin; target.anchorMax = source_rect.anchorMax; target.anchoredPosition = source_rect.anchoredPosition; target.sizeDelta = source_rect.sizeDelta; target.pivot = source_rect.pivot; target.transform.SetParent(notification.transform.parent, false); target.transform.SetSiblingIndex(notification.transform.GetSiblingIndex()); target.gameObject.SetActive(true); return target; } /// /// Clear notifications sequence. /// public static void ClearSequence() { NotifyManager.Clear(); } /// /// Set container (parent gameobject). /// /// Container. public virtual void SetContainer(Transform container) { if (container != null) { transform.SetParent(container, false); } } /// /// Returns replacement slide to cache. /// /// Replacement. public static void FreeSlide(RectTransform replacement) { Replacements.Push(replacement); } /// /// Hide notification. /// public abstract void Hide(); #region HideAnimationRotate #if CSHARP_7_3_OR_NEWER /// /// Vertical rotate animation to hide notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] [Obsolete("Renamed to AnimationRotateVertical.")] public static readonly Func AnimationRotate = AnimationRotateMethod; static IEnumerator AnimationRotateMethod(NotificationBase notification) #else /// /// Vertical rotate animation to hide notification. /// /// Notification. /// Animation coroutine. [Obsolete("Renamed to AnimationRotateVertical.")] public static IEnumerator AnimationRotate(NotificationBase notification) #endif { return AnimationRotateVertical(notification); } #if CSHARP_7_3_OR_NEWER /// /// Vertical rotate animation to hide notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationRotateVertical = AnimationRotateVerticalMethod; static IEnumerator AnimationRotateVerticalMethod(NotificationBase notification) #else /// /// Vertical rotate animation to hide notification. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationRotateVertical(NotificationBase notification) #endif { return HideAnimationRotateBase(notification, false, 0.5f); } #if CSHARP_7_3_OR_NEWER /// /// Horizontal rotate animation to hide notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationRotateHorizontal = AnimationRotateHorizontalMethod; static IEnumerator AnimationRotateHorizontalMethod(NotificationBase notification) #else /// /// Horizontal rotate animation to hide notification. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationRotateHorizontal(NotificationBase notification) #endif { return HideAnimationRotateBase(notification, true, 0.5f); } #if CSHARP_7_3_OR_NEWER /// /// Base rotate animation to hide notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] [Obsolete("Renamed to HideAnimationRotateBase.")] public static readonly Func AnimationRotateBase = AnimationRotateBaseMethod; static IEnumerator AnimationRotateBaseMethod(NotificationBase notification, bool isHorizontal, float timeLength) #else /// /// Base rotate animation to hide notification. /// /// Notification. /// Is horizontal> /// Animation length in seconds. /// Animation coroutine. [Obsolete("Renamed to HideAnimationRotateBase.")] public static IEnumerator AnimationRotateBase(NotificationBase notification, bool isHorizontal, float timeLength) #endif { return HideAnimationRotateBase(notification, isHorizontal, timeLength); } #if CSHARP_7_3_OR_NEWER /// /// Base rotate animation to hide notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func HideAnimationRotateBase = HideAnimationRotateBaseMethod; static IEnumerator HideAnimationRotateBaseMethod(NotificationBase notification, bool isHorizontal, float timeLength) #else /// /// Base rotate animation to hide notification. /// /// Notification. /// Is horizontal> /// Animation length in seconds. /// Animation coroutine. public static IEnumerator HideAnimationRotateBase(NotificationBase notification, bool isHorizontal, float timeLength) #endif { var rect = notification.transform as RectTransform; var base_rotation = rect.localRotation.eulerAngles; var end_time = UtilitiesTime.GetTime(notification.UnscaledTime) + timeLength; while (UtilitiesTime.GetTime(notification.UnscaledTime) <= end_time) { var t = 1f - ((end_time - UtilitiesTime.GetTime(notification.UnscaledTime)) / timeLength); var rotation = Mathf.Lerp(0f, 90f, t); rect.localRotation = isHorizontal ? Quaternion.Euler(base_rotation.x, rotation, base_rotation.z) : Quaternion.Euler(rotation, base_rotation.y, base_rotation.z); yield return null; } // return rotation back for future use rect.localRotation = Quaternion.Euler(base_rotation); } #if CSHARP_7_3_OR_NEWER /// /// Rotate animation to hide notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] [Obsolete("AnimationRotate() now supports UnscaledTime.")] public static readonly Func AnimationRotateUnscaledTime = AnimationRotateUnscaledTimeMethod; static IEnumerator AnimationRotateUnscaledTimeMethod(NotificationBase notification) #else /// /// Rotate animation to hide notification. /// /// Notification. /// Animation coroutine. [Obsolete("AnimationRotate() now supports UnscaledTime.")] public static IEnumerator AnimationRotateUnscaledTime(NotificationBase notification) #endif { return AnimationRotateVertical(notification); } #endregion #region HideAnimationCollapse /// /// Base collapse animation. /// /// Animation coroutine. [Obsolete("Renamed to HideAnimationCollapseBase.")] #if CSHARP_7_3_OR_NEWER [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationCollapseBase = AnimationCollapseBaseMethod; static IEnumerator AnimationCollapseBaseMethod(NotificationBase notification, bool isHorizontal, float speed) #else /// /// Base collapse animation. /// /// Notification. /// Is horizontal? /// Animation speed in points per second. /// Animation coroutine. public static IEnumerator AnimationCollapseBase(NotificationBase notification, bool isHorizontal, float speed) #endif { return HideAnimationCollapseBase(notification, isHorizontal, speed); } /// /// Base collapse animation. /// /// Animation coroutine. #if CSHARP_7_3_OR_NEWER [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func HideAnimationCollapseBase = HideAnimationCollapseBaseMethod; static IEnumerator HideAnimationCollapseBaseMethod(NotificationBase notification, bool isHorizontal, float speed) #else /// /// Base collapse animation. /// /// Notification. /// Is horizontal? /// Animation speed in points per second. /// Animation coroutine. public static IEnumerator HideAnimationCollapseBase(NotificationBase notification, bool isHorizontal, float speed) #endif { var rect = notification.transform as RectTransform; var layout = notification.GetComponentInParent(); var axis = isHorizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical; var base_size = isHorizontal ? rect.rect.width : rect.rect.height; var time = base_size / speed; var end_time = UtilitiesTime.GetTime(notification.UnscaledTime) + time; while (UtilitiesTime.GetTime(notification.UnscaledTime) <= end_time) { var t = 1f - ((end_time - UtilitiesTime.GetTime(notification.UnscaledTime)) / time); var size = Mathf.Lerp(base_size, 0f, t); rect.SetSizeWithCurrentAnchors(axis, size); if (layout != null) { layout.NeedUpdateLayout(); } yield return null; } // return height back for future use rect.SetSizeWithCurrentAnchors(axis, base_size); } #if CSHARP_7_3_OR_NEWER /// /// Vertical collapse animation. /// /// Animation coroutine. [Obsolete("Renamed to AnimationCollapseVertical.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationCollapse = AnimationCollapseMethod; static IEnumerator AnimationCollapseMethod(NotificationBase notification) #else /// /// Vertical collapse animation. /// /// Notification. /// Animation coroutine. [Obsolete("Renamed to AnimationCollapseVertical.")] public static IEnumerator AnimationCollapse(NotificationBase notification) #endif { return AnimationCollapseVertical(notification); } #if CSHARP_7_3_OR_NEWER /// /// Vertical collapse animation. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationCollapseVertical = AnimationCollapseVerticalMethod; static IEnumerator AnimationCollapseVerticalMethod(NotificationBase notification) #else /// /// Vertical collapse animation. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationCollapseVertical(NotificationBase notification) #endif { return HideAnimationCollapseBase(notification, false, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Horizontal collapse animation. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationCollapseHorizontal = AnimationCollapseHorizontalMethod; static IEnumerator AnimationCollapseHorizontalMethod(NotificationBase notification) #else /// /// Horizontal collapse animation. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationCollapseHorizontal(NotificationBase notification) #endif { return HideAnimationCollapseBase(notification, true, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Vertical collapse animation. /// /// Animation coroutine. [Obsolete("AnimationCollapse now supports UnscaledTime.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationCollapseUnscaledTime = AnimationCollapseUnscaledTimeMethod; static IEnumerator AnimationCollapseUnscaledTimeMethod(NotificationBase notification) #else /// /// Vertical collapse animation. /// /// Notification. /// Animation coroutine. [Obsolete("AnimationCollapse now supports UnscaledTime.")] public static IEnumerator AnimationCollapseUnscaledTime(NotificationBase notification) #endif { return AnimationCollapseVertical(notification); } #endregion #region HideAnimationSlide #if CSHARP_7_3_OR_NEWER /// /// Slide animation to hide notification to right. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationSlideRight = AnimationSlideRightMethod; static IEnumerator AnimationSlideRightMethod(NotificationBase notification) #else /// /// Slide animation to hide notification to right. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationSlideRight(NotificationBase notification) #endif { return HideAnimationSlideBase(notification, true, +1f, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Slide animation to hide notification to left. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationSlideLeft = AnimationSlideLeftMethod; static IEnumerator AnimationSlideLeftMethod(NotificationBase notification) #else /// /// Slide animation to hide notification to left. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationSlideLeft(NotificationBase notification) #endif { return HideAnimationSlideBase(notification, true, -1f, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Slide animation to hide notification to top. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationSlideUp = AnimationSlideUpMethod; static IEnumerator AnimationSlideUpMethod(NotificationBase notification) #else /// /// Slide animation to hide notification to top. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationSlideUp(NotificationBase notification) #endif { return HideAnimationSlideBase(notification, false, +1f, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Slide animation to hide notification to bottom. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func AnimationSlideDown = AnimationSlideDownMethod; static IEnumerator AnimationSlideDownMethod(NotificationBase notification) #else /// /// Slide animation to hide notification to bottom. /// /// Notification. /// Animation coroutine. public static IEnumerator AnimationSlideDown(NotificationBase notification) #endif { return HideAnimationSlideBase(notification, false, -1f, 200f); } /// /// Base slide animation to hide notification. /// /// Notification. /// Is horizontal slide? /// Slide direction. /// Speed. /// Animate other notifications. /// Animation coroutine. [Obsolete("Renamed to AnimationSlideBaseHide.")] public static IEnumerator AnimationSlideBase(NotificationBase notification, bool isHorizontal, float direction, float speed, bool animateOthers = true) { return HideAnimationSlideBase(notification, isHorizontal, direction, speed, animateOthers); } /// /// Base slide animation. /// /// Notification. /// Is horizontal slide? /// Slide direction. /// Speed. /// Animate other notifications. /// Animation coroutine. public static IEnumerator HideAnimationSlideBase(NotificationBase notification, bool isHorizontal, float direction, float speed, bool animateOthers = true) { var replacement = GetReplacement(notification); var layout_element = Utilities.GetOrAddComponent(notification); layout_element.ignoreLayout = true; var layout = notification.GetComponentInParent(); var rect = notification.transform as RectTransform; var base_size = isHorizontal ? rect.rect.width : rect.rect.height; var base_pos = rect.anchoredPosition; var time = base_size / speed; var end_time = UtilitiesTime.GetTime(notification.UnscaledTime) + time; var axis = isHorizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical; while (UtilitiesTime.GetTime(notification.UnscaledTime) <= end_time) { if (!animateOthers) { base_pos = replacement.anchoredPosition; } var t = 1 - ((end_time - UtilitiesTime.GetTime(notification.UnscaledTime)) / time); var size = Mathf.Lerp(0, base_size, t); rect.anchoredPosition = isHorizontal ? new Vector2(base_pos.x + (size * direction), base_pos.y) : new Vector2(base_pos.x, base_pos.y + (size * direction)); if (animateOthers) { replacement.SetSizeWithCurrentAnchors(axis, base_size - size); if (layout != null) { layout.NeedUpdateLayout(); } } yield return null; } layout_element.ignoreLayout = false; Replacements.Push(replacement); replacement.gameObject.SetActive(false); replacement.SetSizeWithCurrentAnchors(axis, base_size); if (layout != null) { layout.NeedUpdateLayout(); } } #endregion #region ShowAnimationSlide #if CSHARP_7_3_OR_NEWER /// /// Slide animation to show notification from right. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationSlideRight = ShowAnimationSlideRightMethod; static IEnumerator ShowAnimationSlideRightMethod(NotificationBase notification) #else /// /// Slide animation to show notification from right. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationSlideRight(NotificationBase notification) #endif { return ShowAnimationSlideBase(notification, true, +1f, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Slide animation to show notification from left. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationSlideLeft = ShowAnimationSlideLeftMethod; static IEnumerator ShowAnimationSlideLeftMethod(NotificationBase notification) #else /// /// Slide animation to show notification from left. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationSlideLeft(NotificationBase notification) #endif { return ShowAnimationSlideBase(notification, true, -1f, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Slide animation to show notification from top. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationSlideUp = ShowAnimationSlideUpMethod; static IEnumerator ShowAnimationSlideUpMethod(NotificationBase notification) #else /// /// Slide animation to show notification from top. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationSlideUp(NotificationBase notification) #endif { return ShowAnimationSlideBase(notification, false, +1f, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Slide animation to show notification from bottom. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationSlideDown = ShowAnimationSlideDownMethod; static IEnumerator ShowAnimationSlideDownMethod(NotificationBase notification) #else /// /// Slide animation to show notification from bottom. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationSlideDown(NotificationBase notification) #endif { return ShowAnimationSlideBase(notification, false, -1f, 200f); } /// /// Base slide animation to show notification. /// /// Notification. /// Is horizontal slide? /// Slide direction. /// Speed. /// Animate other notifications. /// Animation coroutine. public static IEnumerator ShowAnimationSlideBase(NotificationBase notification, bool isHorizontal, float direction, float speed, bool animateOthers = true) { var layout = notification.GetComponentInParent(); if (layout != null) { layout.UpdateLayout(); } var replacement = GetReplacement(notification); var layout_element = Utilities.GetOrAddComponent(notification); layout_element.ignoreLayout = true; var rect = notification.transform as RectTransform; var base_size = isHorizontal ? rect.rect.width : rect.rect.height; var base_pos = rect.anchoredPosition; var time = base_size / speed; var end_time = UtilitiesTime.GetTime(notification.UnscaledTime) + time; var axis = isHorizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical; while (UtilitiesTime.GetTime(notification.UnscaledTime) <= end_time) { if (!animateOthers) { base_pos = replacement.anchoredPosition; } var t = 1 - ((end_time - UtilitiesTime.GetTime(notification.UnscaledTime)) / time); var size = Mathf.Lerp(base_size, 0, t); rect.anchoredPosition = isHorizontal ? new Vector2(base_pos.x + (size * direction), base_pos.y) : new Vector2(base_pos.x, base_pos.y + (size * direction)); if (animateOthers) { replacement.SetSizeWithCurrentAnchors(axis, base_size - size); if (layout != null) { layout.NeedUpdateLayout(); } } yield return null; } layout_element.ignoreLayout = false; Replacements.Push(replacement); replacement.gameObject.SetActive(false); replacement.SetSizeWithCurrentAnchors(axis, base_size); if (layout != null) { layout.NeedUpdateLayout(); } } #endregion #region ShowAnimationExplode #if CSHARP_7_3_OR_NEWER /// /// Base explode animation to show notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationExplodeBase = ShowAnimationExplodeBaseMethod; static IEnumerator ShowAnimationExplodeBaseMethod(NotificationBase notification, bool isHorizontal, float speed) #else /// /// Base explode animation to show notification. /// /// Notification. /// Is horizontal? /// Animation speed in points per second. /// Animation coroutine. public static IEnumerator ShowAnimationExplodeBase(NotificationBase notification, bool isHorizontal, float speed) #endif { var rect = notification.transform as RectTransform; var layout = notification.GetComponentInParent(); var axis = isHorizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical; var base_size = isHorizontal ? rect.rect.width : rect.rect.height; var time = base_size / speed; var end_time = UtilitiesTime.GetTime(notification.UnscaledTime) + time; while (UtilitiesTime.GetTime(notification.UnscaledTime) <= end_time) { var t = 1f - ((end_time - UtilitiesTime.GetTime(notification.UnscaledTime)) / time); var size = Mathf.Lerp(0f, base_size, t); rect.SetSizeWithCurrentAnchors(axis, size); if (layout != null) { layout.NeedUpdateLayout(); } yield return null; } // return height back for future use rect.SetSizeWithCurrentAnchors(axis, base_size); } #if CSHARP_7_3_OR_NEWER /// /// Vertical explode animation to show notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationExplodeVertical = ShowAnimationExplodeVerticalMethod; static IEnumerator ShowAnimationExplodeVerticalMethod(NotificationBase notification) #else /// /// Vertical explode animation to show notification. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationExplodeVertical(NotificationBase notification) #endif { return ShowAnimationExplodeBase(notification, false, 200f); } #if CSHARP_7_3_OR_NEWER /// /// Horizontal explode animation to show notification. /// /// Animation coroutine. public static readonly Func ShowAnimationExplodeHorizontal = ShowAnimationExplodeHorizontalMethod; static IEnumerator ShowAnimationExplodeHorizontalMethod(NotificationBase notification) #else /// /// Horizontal explode animation to show notification. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationExplodeHorizontal(NotificationBase notification) #endif { return ShowAnimationExplodeBase(notification, true, 200f); } #endregion #region ShowAnimationRotate #if CSHARP_7_3_OR_NEWER /// /// Vertical rotate animation to show notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationRotateVertical = ShowAnimationRotateVerticalMethod; static IEnumerator ShowAnimationRotateVerticalMethod(NotificationBase notification) #else /// /// Vertical rotate animation to show notification. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationRotateVertical(NotificationBase notification) #endif { return ShowAnimationRotateBase(notification, false, 0.5f); } #if CSHARP_7_3_OR_NEWER /// /// Horizontal rotate animation to show notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationRotateHorizontal = ShowAnimationRotateHorizontalMethod; static IEnumerator ShowAnimationRotateHorizontalMethod(NotificationBase notification) #else /// /// Horizontal rotate animation to show notification. /// /// Notification. /// Animation coroutine. public static IEnumerator ShowAnimationRotateHorizontal(NotificationBase notification) #endif { return ShowAnimationRotateBase(notification, true, 0.5f); } #if CSHARP_7_3_OR_NEWER /// /// Base rotate animation to show notification. /// /// Animation coroutine. [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Cached")] public static readonly Func ShowAnimationRotateBase = ShowAnimationRotateBaseMethod; static IEnumerator ShowAnimationRotateBaseMethod(NotificationBase notification, bool isHorizontal, float timeLength) #else /// /// Base rotate animation to show notification. /// /// Notification. /// Is horizontal> /// Animation length in seconds. /// Animation coroutine. public static IEnumerator ShowAnimationRotateBase(NotificationBase notification, bool isHorizontal, float timeLength) #endif { var rect = notification.transform as RectTransform; var base_rotation = rect.localRotation.eulerAngles; var end_time = UtilitiesTime.GetTime(notification.UnscaledTime) + timeLength; while (UtilitiesTime.GetTime(notification.UnscaledTime) <= end_time) { var t = 1f - ((end_time - UtilitiesTime.GetTime(notification.UnscaledTime)) / timeLength); var rotation = Mathf.Lerp(90f, 0f, t); rect.localRotation = isHorizontal ? Quaternion.Euler(base_rotation.x, rotation, base_rotation.z) : Quaternion.Euler(rotation, base_rotation.y, base_rotation.z); yield return null; } // return rotation back for future use rect.localRotation = Quaternion.Euler(base_rotation); } #endregion } }