Ejemplo n.º 1
0
            public bool IsVisibleForBoolCondition(OCBoolPropertyToggleAttribute boolCondition)
            {
                // If there is no boolCondition, it is allowed to be visible, there is nothing to hide it.
                if (boolCondition == null)
                {
                    //Debug.Log("The '[BoolPropertyToggle]' is not attributed to this " + PublicName + " property field.");
                    return(true);
                }

                //Gets the Property or Field for the boolean
                OCPropertyField boolPropertyField = null;

                OCPropertyField.GetPropertyOrField
                    (out boolPropertyField
                    , boolCondition.BooleanField
                    , Instance
                    , null
                    );

                if (boolPropertyField == null)
                {
                    //If the field in boolCondition.BooleanField doesn't exist.
                    Debug.LogError("The '[BoolPropertyToggle(" + boolCondition.BooleanField + ", " + boolCondition.EqualsValue + ")]' failed. The field '" + boolCondition.BooleanField + "' does not exisit in '" + Instance + "'.");
                    return(true);
                }

                if (boolPropertyField.CSType != typeof(bool))
                {
                    //If the wanted field is not a bool
                    Debug.LogError("The '[BoolPropertyToggle(" + boolCondition.BooleanField + ", " + boolCondition.EqualsValue + ")]' failed. The field '" + boolCondition.BooleanField + "' is not a type of bool in '" + Instance + "'.");
                    return(true);
                }

                //Finds the current value
                bool currentValue = (bool)boolPropertyField.GetValue();

                //Tests if the current Value is equal to the value it should be to be shown
                if (currentValue == boolCondition.EqualsValue)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Ejemplo n.º 2
0
	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();
	}