OutlineSettingsInstance.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. [Serializable]
  8. internal class OutlineSettingsInstance : IOutlineSettings
  9. {
  10. #region data
  11. #pragma warning disable 0649
  12. // NOTE: There are custom editors for public components, so no need to show these in default inspector.
  13. [SerializeField, HideInInspector]
  14. private OutlineSettings _outlineSettings;
  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. #pragma warning restore 0649
  26. #endregion
  27. #region interface
  28. public bool RequiresCameraDepth
  29. {
  30. get
  31. {
  32. return (OutlineRenderMode & OutlineRenderFlags.EnableDepthTesting) != 0;
  33. }
  34. }
  35. public OutlineSettings OutlineSettings
  36. {
  37. get
  38. {
  39. return _outlineSettings;
  40. }
  41. set
  42. {
  43. _outlineSettings = value;
  44. }
  45. }
  46. #endregion
  47. #region IOutlineSettings
  48. /// <inheritdoc/>
  49. public Color OutlineColor
  50. {
  51. get
  52. {
  53. return _outlineSettings is null ? _outlineColor : _outlineSettings.OutlineColor;
  54. }
  55. set
  56. {
  57. _outlineColor = value;
  58. }
  59. }
  60. /// <inheritdoc/>
  61. public int OutlineWidth
  62. {
  63. get
  64. {
  65. return _outlineSettings is null ? _outlineWidth : _outlineSettings.OutlineWidth;
  66. }
  67. set
  68. {
  69. _outlineWidth = Mathf.Clamp(value, OutlineResources.MinWidth, OutlineResources.MaxWidth);
  70. }
  71. }
  72. /// <inheritdoc/>
  73. public float OutlineIntensity
  74. {
  75. get
  76. {
  77. return _outlineSettings is null ? _outlineIntensity : _outlineSettings.OutlineIntensity;
  78. }
  79. set
  80. {
  81. _outlineIntensity = Mathf.Clamp(value, OutlineResources.MinIntensity, OutlineResources.MaxIntensity);
  82. }
  83. }
  84. /// <inheritdoc/>
  85. public float OutlineAlphaCutoff
  86. {
  87. get
  88. {
  89. return _outlineSettings is null ? _outlineAlphaCutoff : _outlineSettings.OutlineAlphaCutoff;
  90. }
  91. set
  92. {
  93. _outlineAlphaCutoff = Mathf.Clamp(value, 0, 1);
  94. }
  95. }
  96. /// <inheritdoc/>
  97. public OutlineRenderFlags OutlineRenderMode
  98. {
  99. get
  100. {
  101. return _outlineSettings is null ? _outlineMode : _outlineSettings.OutlineRenderMode;
  102. }
  103. set
  104. {
  105. _outlineMode = value;
  106. }
  107. }
  108. #endregion
  109. #region IEquatable
  110. public bool Equals(IOutlineSettings other)
  111. {
  112. return OutlineSettings.Equals(this, other);
  113. }
  114. #endregion
  115. #region implementation
  116. #endregion
  117. }
  118. }