UniWebViewShadow.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // UniWebViewShadow.cs
  3. // Created by Wang Wei(@onevcat) on 2025-10-31.
  4. //
  5. // This file is a part of UniWebView Project (https://uniwebview.com)
  6. // By purchasing the asset, you are allowed to use this code in as many as projects
  7. // you want, only if you publish the final products under the name of the same account
  8. // used for the purchase.
  9. //
  10. // This asset and all corresponding files (such as source code) are provided on an
  11. // “as is” basis, without warranty of any kind, express of implied, including but not
  12. // limited to the warranties of merchantability, fitness for a particular purpose, and
  13. // noninfringement. In no event shall the authors or copyright holders be liable for any
  14. // claim, damages or other liability, whether in action of contract, tort or otherwise,
  15. // arising from, out of or in connection with the software or the use of other dealing in the software.
  16. //
  17. using UnityEngine;
  18. /// <summary>
  19. /// Represents the shadow styling applied to a UniWebView instance.
  20. /// </summary>
  21. public readonly struct UniWebViewShadow {
  22. /// <summary>
  23. /// Shadow blur radius.
  24. /// </summary>
  25. public float Radius { get; }
  26. /// <summary>
  27. /// Shadow opacity (0 - 1).
  28. /// </summary>
  29. public float Opacity { get; }
  30. /// <summary>
  31. /// Shadow offset on X axis.
  32. /// </summary>
  33. public float OffsetX { get; }
  34. /// <summary>
  35. /// Shadow offset on Y axis.
  36. /// </summary>
  37. public float OffsetY { get; }
  38. /// <summary>
  39. /// Additional spread distance applied to the shadow outline.
  40. /// </summary>
  41. public float Spread { get; }
  42. /// <summary>
  43. /// Shadow color.
  44. /// </summary>
  45. public Color Color { get; }
  46. /// <summary>
  47. /// Creates a shadow definition.
  48. /// </summary>
  49. public UniWebViewShadow(
  50. float radius,
  51. float opacity,
  52. float offsetX,
  53. float offsetY,
  54. Color color,
  55. float spread = 0.0f
  56. ) {
  57. Radius = Mathf.Max(0.0f, radius);
  58. Opacity = Mathf.Clamp01(opacity);
  59. OffsetX = offsetX;
  60. OffsetY = offsetY;
  61. Color = color;
  62. Spread = Mathf.Max(0.0f, spread);
  63. }
  64. /// <summary>
  65. /// A shadow definition that disables any shadow drawing.
  66. /// </summary>
  67. public static UniWebViewShadow None => new UniWebViewShadow(0.0f, 0.0f, 0.0f, 0.0f, Color.black, 0.0f);
  68. /// <summary>
  69. /// Indicates whether the shadow should be rendered.
  70. /// </summary>
  71. public bool IsVisible =>
  72. Opacity > 0.0f &&
  73. (Radius > 0.0f || Spread > 0.0f);
  74. }