OutlineSettings.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright (C) 2019-2021 Alexander Bogarsukov. All rights reserved.
  2. // See the LICENSE.md file in the project root for more information.
  3. using System;
  4. using UnityEngine;
  5. namespace UnityFx.Outline
  6. {
  7. /// <summary>
  8. /// Outline settings.
  9. /// </summary>
  10. [CreateAssetMenu(fileName = "OutlineSettings", menuName = "UnityFx/Outline/Outline Settings")]
  11. public sealed class OutlineSettings : ScriptableObject, IOutlineSettings
  12. {
  13. #region data
  14. // NOTE: There is a custom editor for OutlineSettings, so no need to show these in default inspector.
  15. [SerializeField, HideInInspector]
  16. private Color _outlineColor = Color.red;
  17. [SerializeField, HideInInspector, Range(OutlineResources.MinWidth, OutlineResources.MaxWidth)]
  18. private int _outlineWidth = 4;
  19. [SerializeField, HideInInspector, Range(OutlineResources.MinIntensity, OutlineResources.MaxIntensity)]
  20. private float _outlineIntensity = 2;
  21. [SerializeField, HideInInspector, Range(OutlineResources.MinAlphaCutoff, OutlineResources.MaxAlphaCutoff)]
  22. private float _outlineAlphaCutoff = 0.9f;
  23. [SerializeField, HideInInspector]
  24. private OutlineRenderFlags _outlineMode;
  25. #endregion
  26. #region interface
  27. public static bool Equals(IOutlineSettings lhs, IOutlineSettings rhs)
  28. {
  29. if (lhs == null || rhs == null)
  30. {
  31. return false;
  32. }
  33. return lhs.OutlineColor == rhs.OutlineColor &&
  34. lhs.OutlineWidth == rhs.OutlineWidth &&
  35. lhs.OutlineRenderMode == rhs.OutlineRenderMode &&
  36. Mathf.Approximately(lhs.OutlineIntensity, rhs.OutlineIntensity) &&
  37. Mathf.Approximately(lhs.OutlineAlphaCutoff, rhs.OutlineAlphaCutoff);
  38. }
  39. #endregion
  40. #region IOutlineSettings
  41. /// <inheritdoc/>
  42. public Color OutlineColor
  43. {
  44. get
  45. {
  46. return _outlineColor;
  47. }
  48. set
  49. {
  50. _outlineColor = value;
  51. }
  52. }
  53. /// <inheritdoc/>
  54. public int OutlineWidth
  55. {
  56. get
  57. {
  58. return _outlineWidth;
  59. }
  60. set
  61. {
  62. _outlineWidth = Mathf.Clamp(value, OutlineResources.MinWidth, OutlineResources.MaxWidth);
  63. }
  64. }
  65. /// <inheritdoc/>
  66. public float OutlineIntensity
  67. {
  68. get
  69. {
  70. return _outlineIntensity;
  71. }
  72. set
  73. {
  74. _outlineIntensity = Mathf.Clamp(value, OutlineResources.MinIntensity, OutlineResources.MaxIntensity);
  75. }
  76. }
  77. /// <inheritdoc/>
  78. public float OutlineAlphaCutoff
  79. {
  80. get
  81. {
  82. return _outlineAlphaCutoff;
  83. }
  84. set
  85. {
  86. _outlineAlphaCutoff = Mathf.Clamp(value, 0, 1);
  87. }
  88. }
  89. /// <inheritdoc/>
  90. public OutlineRenderFlags OutlineRenderMode
  91. {
  92. get
  93. {
  94. return _outlineMode;
  95. }
  96. set
  97. {
  98. _outlineMode = value;
  99. }
  100. }
  101. #endregion
  102. #region IEquatable
  103. /// <inheritdoc/>
  104. public bool Equals(IOutlineSettings other)
  105. {
  106. return Equals(this, other);
  107. }
  108. #endregion
  109. #region Object
  110. /// <inheritdoc/>
  111. public override bool Equals(object other)
  112. {
  113. return Equals(this, other as IOutlineSettings);
  114. }
  115. /// <inheritdoc/>
  116. public override int GetHashCode()
  117. {
  118. return base.GetHashCode();
  119. }
  120. #endregion
  121. }
  122. }