/// <summary>
    /// Show input fields for all parameters of the given method
    /// </summary>
    /// <param name="theMethod">The reflected method info</param>
    static void ListParameters(UnityEngine.Object theTarget, KGFEvent.KGFEventData theEventData, MethodInfo theMethod)
    {
        if (theEventData.GetDirectPassThroughMode())
        {
            return;
        }
//		if (!theEventData.GetDisplayParametersInInspector())
//			return;

        EditorGUILayout.BeginHorizontal();
//		EditorGUILayout.Space();

        EditorGUILayout.BeginVertical();
        {
            // get parameters from method
            ParameterInfo [] aMethodParametersList = theMethod.GetParameters();
            // get saved parameter values from event_generic object
            KGFEvent.EventParameter [] aParametersList = theEventData.GetParameters();
            // reinit parameter values if length counts do not match
            if (theEventData.itsParameters.Length != aMethodParametersList.Length)
            {
                aParametersList = new KGFEvent.EventParameter[aMethodParametersList.Length];
                for (int j = 0; j < aParametersList.Length; j++)
                {
                    aParametersList[j] = new KGFEvent.EventParameter();
                }
            }

            KGFEvent.EventParameterType[] aTypes = theEventData.GetParameterLinkTypes();
            string[] aPopUpArray = new string[0];

            // draw input field for each parameter
            for (int i = 0; i < aMethodParametersList.Length; i++)
            {
                GUILayout.BeginHorizontal();
                {
                    // check if there are linked parameters with the current parameter type
                    if (theEventData.GetSupportsRuntimeParameterInfos())
                    {
                        List <string> aPopupList = new List <string>();
                        foreach (KGFEvent.EventParameterType aParameterType in aTypes)
                        {
                            if (aParameterType.GetIsMatchingType(aMethodParametersList[i].ParameterType))
                            {
                                aPopupList.Add(string.Format("{0} ({1})", aParameterType.itsName, aParameterType.itsTypeName));
                            }
                        }
                        aPopUpArray = aPopupList.ToArray();
                    }

//					if (i < aMethodParametersList.Length-1)
                    {
                        GUILayout.Label("├", GUILayout.Width(20));
                    }
//					else
//					{
//						GUILayout.Label("└",GUILayout.Width(20));
//					}

                    if (theEventData.GetIsParameterLinked(i))
                    {
                        // if the parameter is linked, let the user choose the linked parameter
                        GUILayout.Label(aMethodParametersList[i].Name + "=");
                        int aIndexNew = EditorGUILayout.Popup(theEventData.GetParameterLink(i), aPopUpArray);
                        if (aIndexNew != theEventData.GetParameterLink(i))
                        {
                            theEventData.SetParameterLink(i, aIndexNew);
                            EditorUtility.SetDirty(theTarget);
                        }
                    }
                    else
                    {
                        // if not linked, enable default input field
                        DrawSingleParameter(theTarget, theEventData, aMethodParametersList[i], aParametersList[i], i);
                    }

                    // let the user enable/disable linked state for this parameter, if it is supported and there are parameters with matching types
                    if (theEventData.GetSupportsRuntimeParameterInfos() && aPopUpArray.Length > 0)
                    {
                        bool aBoolValue = GUILayout.Toggle(theEventData.GetIsParameterLinked(i), "Link", GUILayout.Width(40));
                        if (aBoolValue != theEventData.GetIsParameterLinked(i))
                        {
                            theEventData.SetIsParameterLinked(i, aBoolValue);
                            EditorUtility.SetDirty(theTarget);
                        }
                    }
                    else
                    {
                        theEventData.SetIsParameterLinked(i, false);
                    }
                }
                GUILayout.EndHorizontal();
            }
            // save parameter values to the event generic object
            theEventData.SetParameters(aParametersList);
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.EndHorizontal();
    }
 /// <summary>
 /// Draw a single parameter field
 /// </summary>
 /// <param name="theParameter">The reflected parameter type</param>
 /// <param name="theValue">The parameter value</param>
 /// <param name="theIndex">Index of the parameter in the itsParameters array</param>
 static void DrawSingleParameter(UnityEngine.Object theTarget, KGFEvent.KGFEventData theEventData, ParameterInfo theParameter, KGFEvent.EventParameter theValue, int theIndex)
 {
     if (typeof(UnityEngine.Object).IsAssignableFrom(theParameter.ParameterType))
     {
         // if the parameter is derrived from unityengine.object, display an object field
         UnityEngine.Object aObject = EditorGUILayout.ObjectField(theParameter.Name, theValue.itsValueUnityObject, theParameter.ParameterType, true);
         if (aObject != theValue.itsValueUnityObject)
         {
             EditorUtility.SetDirty(theTarget);
             theValue.itsValueUnityObject = aObject;
         }
     }
     else
     {
         // Search for parameter with right name in EventParameter script and display it
         if (typeof(int).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueInt32 = (int)KGFGUIUtilityEditor.DrawField(theTarget, typeof(int), theParameter.Name, theValue.itsValueInt32);
         }
         else if (typeof(double).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueSingle = (float)KGFGUIUtilityEditor.DrawField(theTarget, typeof(float), theParameter.Name, theValue.itsValueSingle);
         }
         else if (typeof(float).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueDouble = (double)KGFGUIUtilityEditor.DrawField(theTarget, typeof(double), theParameter.Name, theValue.itsValueDouble);
         }
         else if (typeof(string).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueString = (string)KGFGUIUtilityEditor.DrawField(theTarget, typeof(string), theParameter.Name, theValue.itsValueString);
         }
         else if (typeof(Color).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueColor = (Color)KGFGUIUtilityEditor.DrawField(theTarget, typeof(Color), theParameter.Name, theValue.itsValueColor);
         }
         else if (typeof(Rect).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueRect = (Rect)KGFGUIUtilityEditor.DrawField(theTarget, typeof(Rect), theParameter.Name, theValue.itsValueRect);
         }
         else if (typeof(Vector2).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueVector2 = (Vector2)KGFGUIUtilityEditor.DrawField(theTarget, typeof(Vector2), theParameter.Name, theValue.itsValueVector2);
         }
         else if (typeof(Vector3).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueVector3 = (Vector3)KGFGUIUtilityEditor.DrawField(theTarget, typeof(Vector3), theParameter.Name, theValue.itsValueVector3);
         }
         else if (typeof(Vector4).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueVector4 = (Vector4)KGFGUIUtilityEditor.DrawField(theTarget, typeof(Vector4), theParameter.Name, theValue.itsValueVector4);
         }
         else if (typeof(bool).IsAssignableFrom(theParameter.ParameterType))
         {
             theValue.itsValueBoolean = (bool)KGFGUIUtilityEditor.DrawField(theTarget, typeof(bool), theParameter.Name, theValue.itsValueBoolean);
         }
         else if (typeof(Enum).IsAssignableFrom(theParameter.ParameterType))
         {
             Enum anEnumValue = null;
             try{
                 anEnumValue = (Enum)Enum.Parse(theParameter.ParameterType, theValue.itsValueString);
             }
             catch
             {
                 // choose first value of enum
                 foreach (Enum aValue in Enum.GetValues(theParameter.ParameterType))
                 {
                     anEnumValue = aValue;
                     break;
                 }
             }
             theValue.itsValueString = ((Enum)KGFGUIUtilityEditor.DrawField(theTarget, typeof(Enum), theParameter.Name, anEnumValue)).ToString();
         }
     }
 }
Ejemplo n.º 3
0
	/// <summary>
	/// Show input fields for all parameters of the given method
	/// </summary>
	/// <param name="theMethod">The reflected method info</param>
	static void ListParameters(UnityEngine.Object theTarget, KGFEvent.KGFEventData theEventData, MethodInfo theMethod)
	{
		if (theEventData.GetDirectPassThroughMode())
			return;
//		if (!theEventData.GetDisplayParametersInInspector())
//			return;

		EditorGUILayout.BeginHorizontal();
//		EditorGUILayout.Space();

		EditorGUILayout.BeginVertical();
		{
			// get parameters from method
			ParameterInfo [] aMethodParametersList = theMethod.GetParameters();
			// get saved parameter values from event_generic object
			KGFEvent.EventParameter []aParametersList = theEventData.GetParameters();
			// reinit parameter values if length counts do not match
			if (theEventData.itsParameters.Length != aMethodParametersList.Length)
			{
				aParametersList = new KGFEvent.EventParameter[aMethodParametersList.Length];
				for (int j=0;j<aParametersList.Length;j++)
				{
					aParametersList[j] = new KGFEvent.EventParameter();
				}
			}
			
			KGFEvent.EventParameterType[] aTypes = theEventData.GetParameterLinkTypes();
			string[] aPopUpArray = new string[0];
			
			// draw input field for each parameter
			for (int i=0;i<aMethodParametersList.Length;i++)
			{
				GUILayout.BeginHorizontal();
				{
					// check if there are linked parameters with the current parameter type
					if (theEventData.GetSupportsRuntimeParameterInfos())
					{
						List<string> aPopupList = new List<string>();
						foreach (KGFEvent.EventParameterType aParameterType in aTypes)
						{
							if (aParameterType.GetIsMatchingType(aMethodParametersList[i].ParameterType))
							{
								aPopupList.Add(string.Format("{0} ({1})",aParameterType.itsName,aParameterType.itsTypeName));
							}
						}
						aPopUpArray = aPopupList.ToArray();
					}
					
//					if (i < aMethodParametersList.Length-1)
					{
						GUILayout.Label("├",GUILayout.Width(20));
					}
//					else
//					{
//						GUILayout.Label("└",GUILayout.Width(20));
//					}
					
					if (theEventData.GetIsParameterLinked(i))
					{
						// if the parameter is linked, let the user choose the linked parameter
						GUILayout.Label(aMethodParametersList[i].Name+"=");
						int aIndexNew = EditorGUILayout.Popup(theEventData.GetParameterLink(i),aPopUpArray);
						if (aIndexNew != theEventData.GetParameterLink(i))
						{
							theEventData.SetParameterLink(i,aIndexNew);
							EditorUtility.SetDirty(theTarget);
						}
					}
					else
					{
						// if not linked, enable default input field
						DrawSingleParameter(theTarget,theEventData,aMethodParametersList[i],aParametersList[i],i);
					}
					
					// let the user enable/disable linked state for this parameter, if it is supported and there are parameters with matching types
					if (theEventData.GetSupportsRuntimeParameterInfos() && aPopUpArray.Length > 0)
					{
						bool aBoolValue = GUILayout.Toggle(theEventData.GetIsParameterLinked(i),"Link",GUILayout.Width(40));
						if (aBoolValue != theEventData.GetIsParameterLinked(i))
						{
							theEventData.SetIsParameterLinked(i,aBoolValue);
							EditorUtility.SetDirty(theTarget);
						}
					}else
					{
						theEventData.SetIsParameterLinked(i,false);
					}
				}
				GUILayout.EndHorizontal();
			}
			// save parameter values to the event generic object
			theEventData.SetParameters(aParametersList);
		}
		EditorGUILayout.EndVertical();

		EditorGUILayout.EndHorizontal();
	}