using UnityEngine; namespace Unity.Services.Mediation { /// /// Specifies a size for a Banner Ad. /// public class BannerAdSize { const float k_DpiPerDp = 160f; #if UNITY_EDITOR //This value is approximative, for use in mock banners only internal static readonly float k_DpToPixelRatio = 2.5f * Screen.width / 1080f; #else internal static readonly float k_DpToPixelRatio = Screen.dpi / k_DpiPerDp; #endif /// /// Retrieves the Width of this Banner Size in pixels. /// public int Width => (int)m_Value.x; /// /// Retrieves the Height of this Banner Size in pixels. /// public int Height => (int)m_Value.y; /// /// Retrieves the Width of this Banner Size in dp. /// public int DpWidth => (int)Mathf.Ceil(m_Value.x / k_DpToPixelRatio); /// /// Retrieves the Height of this Banner Size in dp. /// public int DpHeight => (int)Mathf.Ceil(m_Value.y / k_DpToPixelRatio); readonly Vector2 m_Value; /// /// Constructs a Banner Size in pixel format /// /// Width of Banner in pixels /// Height of Banner in pixels public BannerAdSize(int width, int height) : this(new Vector2(width, height)) { } /// /// Constructs a Banner Size from a Vector2 in pixel format /// /// size in a pixels form public BannerAdSize(Vector2 size) { m_Value = size; } /// /// Constructs a Banner Size from a predefined size /// /// size in a form public BannerAdSize(BannerAdPredefinedSize size) { m_Value = size.ToBannerAdSize().m_Value; } /// /// Constructs a Banner Size from dp units /// /// Width of Banner in dp /// Height of Banner in dp /// A Banner Ad Size based on dp units received public static BannerAdSize FromDpUnits(int dpWidth, int dpHeight) { return new BannerAdSize(new Vector2(dpWidth * k_DpToPixelRatio, dpHeight * k_DpToPixelRatio)); } /// /// Cast to /// /// Banner Ad Size /// version of size public static implicit operator Vector2(BannerAdSize size) { return size?.m_Value ?? Vector2.zero; } /// /// Cast to banner ad size. /// /// Banner ad size. /// Banner ad size object. public static implicit operator BannerAdSize(Vector2 size) { return new BannerAdSize(size); } /// /// Determines object equivalency. /// /// Other object /// whether objects are equal protected bool Equals(BannerAdSize other) { return m_Value.Equals(other.m_Value); } /// /// Determines object equivalency. /// /// Other object /// whether objects are equal public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; return Equals((BannerAdSize)obj); } /// /// Retrieves the hash for this object /// /// object hash public override int GetHashCode() { return m_Value.GetHashCode(); } } }