Exemple #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!(attribute is ReadOnlyAttribute conditional))
            {
                return;
            }

            bool enabled = !ConditionalUtility.IsPropertyConditionMatch(property, conditional.Data);

            GUI.enabled = enabled;
            EditorGUI.PropertyField(position, property, label, true);
            GUI.enabled = true;
        }
        private static bool ExcludeCheckIfConditionalFieldHidden(FieldInfo field, UnityEngine.Object obj)
        {
            if (ConditionalType == null)
            {
                return(false);
            }
            if (!field.IsDefined(ConditionalType, false))
            {
                return(false);
            }

            // Get a specific attribute of this field
            var conditional = field.GetCustomAttributes(ConditionalType, false)
                              .Select(a => a as ConditionalFieldAttribute)
                              .SingleOrDefault();

            return(conditional != null && !ConditionalUtility.IsConditionMatch(obj, conditional.Data));
        }
Exemple #3
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (!(attribute is ConditionalFieldAttribute conditional))
            {
                return(EditorGUI.GetPropertyHeight(property));
            }

            CachePropertyDrawer(property);
            _toShow = ConditionalUtility.IsPropertyConditionMatch(property, conditional.Data);
            if (!_toShow)
            {
                return(0);
            }

            if (_customPropertyDrawer != null)
            {
                return(_customPropertyDrawer.GetPropertyHeight(property, label));
            }
            return(EditorGUI.GetPropertyHeight(property));
        }