public bool IsVisibleForEnumCondition(OCEnumPropertyToggleAttribute enumCondition) { // If there is no enumCondition, it is allowed to be visible, there is nothing to hide it. if (enumCondition == null) { //Debug.Log("The '[EnumPropertyToggle]' is not attributed to this " + PublicName + " property field."); return(true); } //Gets the Property or Field for the enum OCPropertyField enumPropertyField = null; GetPropertyOrField (out enumPropertyField , enumCondition.EnumField , Instance , null ); if (enumPropertyField == null) { //If the field in boolCondition.BooleanField doesn't exist. Debug.LogError("The '[EnumPropertyToggle(" + enumCondition.EnumField + ", " + enumCondition.EnumValue + ")]' failed. The field '" + enumCondition.EnumField + "' does not exisit in '" + Instance + "'."); return(true); } if (enumPropertyField.UnityType != SerializedPropertyType.Enum) { //If the wanted field is not a enum Debug.LogError("The '[EnumPropertyToggle(" + enumCondition.EnumField + ", " + enumCondition.EnumValue + ")]' failed. The field '" + enumCondition.EnumField + "' is not a enum in '" + Instance + "'."); return(true); } //Tests if the fields current value is equal to the value it should be to be shown if (Enum.Equals(enumPropertyField.GetValue(), enumCondition.EnumValue)) { return(true); } else { return(false); } }
public void DrawSerializedProperties(List< OCPropertyField > allPropertiesAndFields) { GUIContent label = new GUIContent(); GUILayoutOption[] emptyOptions = new GUILayoutOption[0]; //EditorGUILayout.BeginVertical(emptyOptions); //Loops through all visible fields foreach(OCPropertyField propertyField in allPropertiesAndFields) { //Debug.Log(propertyField.PublicName + ", " + propertyField.UnityType); //if(propertyField.GetValue() == null) // continue; //EditorGUILayout.BeginHorizontal(emptyOptions); //Finds the bool Condition, enum Condition and tooltip if they exist (They are null otherwise). OCBoolPropertyToggleAttribute boolCondition = propertyField.GetAttribute<OCBoolPropertyToggleAttribute>(); OCEnumPropertyToggleAttribute enumCondition = propertyField.GetAttribute<OCEnumPropertyToggleAttribute>(); OCDrawMethodAttribute drawMethod = propertyField.GetAttribute<OCDrawMethodAttribute>(); OCTooltipAttribute tooltip = propertyField.GetAttribute<OCTooltipAttribute>(); OCFloatSliderAttribute floatSlider = propertyField.GetAttribute<OCFloatSliderAttribute>(); OCIntSliderAttribute intSlider = propertyField.GetAttribute<OCIntSliderAttribute>(); //Evaluates the enum and bool conditions bool allowedVisibleForBoolCondition = propertyField.IsVisibleForBoolCondition(boolCondition); bool allowedVisibleForEnumCondition = propertyField.IsVisibleForEnumCondition(enumCondition); //Tests is the field is visible if(allowedVisibleForBoolCondition && allowedVisibleForEnumCondition && drawMethod == null) { label.text = propertyField.PublicName; //Sets the tooltip if avaiable if(tooltip != null) { label.tooltip = tooltip.Description; } DrawFieldInInspector(propertyField, label, emptyOptions, floatSlider, intSlider); } else if(drawMethod != null) { // If the user wants to draw the field himself. MethodInfo drawMethodInfo = this.GetType().GetMethod(drawMethod.DrawMethod); if(drawMethodInfo == null) { Debug.LogError("The '[CustomDrawMethod(" + drawMethod.DrawMethod + "" + drawMethod.ParametersToString() + ")]' failed. Could not find the method '" + drawMethod.DrawMethod + "' in the " + this.ToString() + ". The attribute is attached to the field '" + propertyField.PublicName + "' in '" + propertyField.UnityPropertyField.serializedObject.targetObject + "'."); continue; } ParameterInfo[] parametersInfo = drawMethodInfo.GetParameters(); if(parametersInfo.Length != (drawMethod.Parameters as object[]).Length) { Debug.LogError("The '[CustomDrawMethod(" + drawMethod.DrawMethod + "" + drawMethod.ParametersToString() + ")]' failed. The number of parameters in the attribute, did not match the number of parameters in the actual method. The attribute is attached to the field '" + propertyField.PublicName + "' in '" + propertyField.UnityPropertyField.serializedObject.targetObject + "'."); continue; } bool _error = false; for(int i = 0; i < parametersInfo.Length; i++) { //Makes sure the parameter of the actual method is equal to the given parameters if(!Type.Equals(parametersInfo[i].ParameterType, drawMethod.Parameters[i].GetType())) { _error = true; Debug.LogError("The '[CustomDrawMethod(" + drawMethod.DrawMethod + "" + drawMethod.ParametersToString() + ")]' failed. The parameter type ('" + drawMethod.Parameters[i].GetType() + "') in the attribute, did not match the the parameter type ('" + parametersInfo[i].ParameterType + "') of the actual method, parameter index: '" + i + "'. The attribute is attached to the field '" + propertyField.PublicName + "' in '" + propertyField.UnityPropertyField.serializedObject.targetObject + "'."); continue; } } if(_error) { continue; } // VVVVV Calls the users own method VVVVV drawMethodInfo.Invoke(this, drawMethod.Parameters); // ^^^^^ Calls the users own method ^^^^^ } else { //Debug.Log("In OCEditor.DrawSerializedProperties, nothing to draw! " + allowedVisibleForBoolCondition + ", " + allowedVisibleForEnumCondition + ", " + drawMethod); } //EditorGUILayout.EndHorizontal(); } //EditorGUILayout.EndVertical(); }