UniWebViewCornerRadius.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // UniWebViewCornerRadius.cs
  3. // Created by Wang Wei(@onevcat) on 2025-10-26.
  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 corner radii of a UniWebView instance.
  20. /// </summary>
  21. public readonly struct UniWebViewCornerRadius {
  22. /// <summary>
  23. /// Corner radius at the top-left corner.
  24. /// </summary>
  25. public float TopLeft { get; }
  26. /// <summary>
  27. /// Corner radius at the top-right corner.
  28. /// </summary>
  29. public float TopRight { get; }
  30. /// <summary>
  31. /// Corner radius at the bottom-left corner.
  32. /// </summary>
  33. public float BottomLeft { get; }
  34. /// <summary>
  35. /// Corner radius at the bottom-right corner.
  36. /// </summary>
  37. public float BottomRight { get; }
  38. /// <summary>
  39. /// Creates a corner radius with individual values for each corner.
  40. /// </summary>
  41. public UniWebViewCornerRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) {
  42. TopLeft = Mathf.Max(0.0f, topLeft);
  43. TopRight = Mathf.Max(0.0f, topRight);
  44. BottomLeft = Mathf.Max(0.0f, bottomLeft);
  45. BottomRight = Mathf.Max(0.0f, bottomRight);
  46. }
  47. /// <summary>
  48. /// Creates a corner radius using the same value for all corners.
  49. /// </summary>
  50. public static UniWebViewCornerRadius Uniform(float radius) {
  51. return new UniWebViewCornerRadius(radius, radius, radius, radius);
  52. }
  53. /// <summary>
  54. /// A corner radius with all corners set to zero.
  55. /// </summary>
  56. public static UniWebViewCornerRadius Zero => new UniWebViewCornerRadius(0.0f, 0.0f, 0.0f, 0.0f);
  57. /// <summary>
  58. /// Determines whether all corners are zero.
  59. /// </summary>
  60. public bool IsZero =>
  61. Mathf.Approximately(TopLeft, 0.0f) &&
  62. Mathf.Approximately(TopRight, 0.0f) &&
  63. Mathf.Approximately(BottomLeft, 0.0f) &&
  64. Mathf.Approximately(BottomRight, 0.0f);
  65. }