| | 1 | | using UnityEngine; |
| | 2 | | using System; |
| | 3 | |
|
| | 4 | | /// <summary> |
| | 5 | | /// Draws the field/property ONLY if the compared property compared by the comparison type with the value of comparedVal |
| | 6 | | /// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/ |
| | 7 | | /// </summary> |
| | 8 | | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)] |
| | 9 | | public class DrawIfAttribute : PropertyAttribute |
| | 10 | | { |
| | 11 | | #region Fields |
| | 12 | |
|
| 0 | 13 | | public string comparedPropertyName { get; private set; } |
| 0 | 14 | | public object comparedValue { get; private set; } |
| 0 | 15 | | public DisablingType disablingType { get; private set; } |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Types of comperisons. |
| | 19 | | /// </summary> |
| | 20 | | public enum DisablingType |
| | 21 | | { |
| | 22 | | ReadOnly = 2, |
| | 23 | | DontDraw = 3 |
| | 24 | | } |
| | 25 | |
|
| | 26 | | #endregion |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Only draws the field only if a condition is met. Supports enum and bools. |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="comparedPropertyName">The name of the property that is being compared (case sensitive).</param> |
| | 32 | | /// <param name="comparedValue">The value the property is being compared to.</param> |
| | 33 | | /// <param name="disablingType">The type of disabling that should happen if the condition is NOT met. Defaulted to D |
| 0 | 34 | | public DrawIfAttribute(string comparedPropertyName, object comparedValue, DisablingType disablingType = DisablingTyp |
| | 35 | | { |
| 0 | 36 | | this.comparedPropertyName = comparedPropertyName; |
| 0 | 37 | | this.comparedValue = comparedValue; |
| 0 | 38 | | this.disablingType = disablingType; |
| 0 | 39 | | } |
| | 40 | | } |