Exemplo n.º 1
0
        private bool GetConditionalHideAttributeResult(BoolConditionWarrningBox condHAtt, SerializedProperty property)
        {
            bool               showWarrning        = true;
            string             propertyPath        = property.propertyPath;
            string             conditionPath       = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField);
            SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);

            if (sourcePropertyValue != null)
            {
                if (sourcePropertyValue.boolValue == property.boolValue)
                {
                    if (condHAtt.bothCondition == true && sourcePropertyValue.boolValue == true)
                    {
                        showWarrning = true;
                    }
                    else if (condHAtt.bothCondition == false && sourcePropertyValue.boolValue == false)
                    {
                        showWarrning = true;
                    }
                    else
                    {
                        showWarrning = false;
                    }
                }
                else
                {
                    showWarrning = false;
                }
            }
            else
            {
                Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField);
            }
            return(showWarrning);
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            BoolConditionWarrningBox condHAtt = (BoolConditionWarrningBox)attribute;
            bool showWarrning = GetConditionalHideAttributeResult(condHAtt, property);

            EditorGUI.PropertyField(position, property, label, true);
            if (showWarrning)
            {
                EditorGUILayout.HelpBox(condHAtt.message, MessageType.Warning);
            }
        }