using UnityEngine; using System; /// /// Draws the field/property ONLY if the compared property compared by the comparison type with the value of comparedValue returns true. /// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/ /// [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)] public class CompareEnumWithRangeAttribute : PropertyAttribute { #region Fields public string comparedPropertyName { get; private set; } public object comparedValue1 { get; private set; } public object comparedValue2 { get; private set; } public object comparedValue3 { get; private set; } public StyleType styleType { get; private set; } public float min; public float max; /// /// Types of styles variables can use. /// public enum StyleType { FloatSlider = 1, IntSlider = 2 } #endregion /// /// Only draws the field only if a condition is met. /// /// The name of the property that is being compared (case sensitive). /// The value the property is being compared to. public CompareEnumWithRangeAttribute(string comparedPropertyName, float min, float max, StyleType styleType, object comparedValue1, object comparedValue2 = null, object comparedValue3 = null) { this.comparedPropertyName = comparedPropertyName; this.min = min; this.max = max; this.styleType = styleType; this.comparedValue1 = comparedValue1; this.comparedValue2 = comparedValue2; this.comparedValue3 = comparedValue3; } }