Esempio n. 1
0
        private void Initialize(SerializedProperty property)
        {
            if (!_conditionalToTarget.ContainsKey(property))
            {
                _conditionalToTarget.Add(property, ConditionalFieldUtility.FindRelativeProperty(property, Conditional.FieldToCheck));
            }

            if (_customDrawersCached)
            {
                return;
            }
            if (_allPropertyDrawerAttributeTypes == null)
            {
                _allPropertyDrawerAttributeTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
                                                   .Where(x => typeof(PropertyDrawer).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
            }

            if (HaveMultipleAttributes())
            {
                _multipleAttributes = true;
                GetPropertyDrawerType(property);
            }
            else if (fieldInfo != null && !fieldInfo.FieldType.Module.ScopeName.Equals(typeof(int).Module.ScopeName))
            {
                _specialType = true;
                GetTypeDrawerType(property);
            }

            _customDrawersCached = true;
        }
Esempio n. 2
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (!(attribute is ConditionalFieldAttribute conditional))
            {
                return(0);
            }

            Initialize(property);

            var propertyToCheck = ConditionalFieldUtility.FindRelativeProperty(property, conditional.FieldToCheck);

            _toShow = ConditionalFieldUtility.PropertyIsVisible(propertyToCheck, conditional.Inverse, conditional.CompareValues);
            if (!_toShow)
            {
                return(0);
            }

            if (_customAttributeDrawer != null)
            {
                return(_customAttributeDrawer.GetPropertyHeight(property, label));
            }
            if (_customTypeDrawer != null)
            {
                return(_customTypeDrawer.GetPropertyHeight(property, label));
            }

            return(EditorGUI.GetPropertyHeight(property));
        }
        public static bool BehaviourPropertyIsVisible(MonoBehaviour behaviour, string propertyName, ConditionalFieldAttribute appliedAttribute)
        {
            if (string.IsNullOrEmpty(appliedAttribute.FieldToCheck))
            {
                return(true);
            }

            var so             = new SerializedObject(behaviour);
            var property       = so.FindProperty(propertyName);
            var targetProperty = ConditionalFieldUtility.FindRelativeProperty(property, appliedAttribute.FieldToCheck);

            return(ConditionalFieldUtility.PropertyIsVisible(targetProperty, appliedAttribute.Inverse, appliedAttribute.CompareValues));
        }
        private static bool ExcludeCheckIfConditionalFieldHidden(FieldInfo field, UnityEngine.Object obj)
        {
            if (_conditionallyVisibleType == null)
            {
                return(false);
            }
            if (!field.IsDefined(_conditionallyVisibleType, false))
            {
                return(false);
            }

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

            return(conditionalFieldAttribute != null &&
                   !ConditionalFieldUtility.BehaviourPropertyIsVisible(obj, field.Name, conditionalFieldAttribute));
        }
Esempio n. 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!(attribute is ReadOnlyAttribute conditional))
            {
                return;
            }

            bool enabled = false;

            if (!string.IsNullOrEmpty(conditional.FieldToCheck))
            {
                var propertyToCheck = ConditionalFieldUtility.FindRelativeProperty(property, conditional.FieldToCheck);
                enabled = !ConditionalFieldUtility.PropertyIsVisible(propertyToCheck, conditional.Inverse, conditional.CompareValues);
            }

            GUI.enabled = enabled;
            EditorGUI.PropertyField(position, property, label, true);
            GUI.enabled = true;
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            Initialize(property);

            _toShow = ConditionalFieldUtility.PropertyIsVisible(_conditionalToTarget[property], _attribute.Inverse, _attribute.CompareValues);
            if (!_toShow)
            {
                return(0);
            }

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