public ComponentMethodParameter(ComponentMethodInfo method)
 {
     ParameterInfo[] parameters = method.RawMethod.GetParameters();
     if (parameters.Length == 1) {
         _rawParameter = parameters[0];
         _type = _rawParameter.ParameterType;
     //				_value = GetDefaultValue(_type);
     }
     else {
         // FIXME throw exception?
     }
 }
Example #2
0
        // TODO create a MethodsPopup that uses EditorGUI instead of EditorGUILayout.
        /// <summary>
        /// Customized EditorGUILayout.Popup for displaying a GameObject's methods.
        /// </summary>
        /// <returns>
        /// Returns the index of the selected popup item.
        /// </returns>
        /// <param name="selectedMethod">
        /// Holds data about the selected component method.
        /// </param>
        public static int ComponentMethodsPopup(string label, int selected, GameObject gameObject, out ComponentMethodInfo selectedMethod)
        {
            // Bail out if there's no object to scan. This will cause the popup control to disappear completely
            if (!gameObject) {
                selectedMethod = null;
                return 0;
            }

            GameObjectInfo _info = new GameObjectInfo (gameObject);
            List<string> _names = new List<string> ();
            List<ComponentMethodInfo> _componentMethods = new List<ComponentMethodInfo> ();

            // Find all accessible methods belonging to the given GameObject
            if (gameObject != null) {
                foreach (ComponentInfo component in _info.Components) {
                    foreach (ComponentMethodInfo method in component.Methods) {
                        // Ignore the Transform component
                        if (component.ComponentType == typeof(Transform))
                            continue;
                        // Find supported parameters
                        string parameterName = "";
                        if (method.HasParameter)
                            parameterName = method.Parameter.ValueTypeName + " ";
                        // Display methods in the form of "ComponentName.MethodName ( parameterType )"
                        // FIXME display a dot in the UI instead of a slash,
                        // but pass a slash to EditorGUI.Popup so that it will generate sub-menus
                        _names.Add (component.Name + "/" + method.Name + " ( " + parameterName + ")");
                        _componentMethods.Add (method);
                    }
                }
            }

            // FIXME this doesn't belong here. Place it where the popup value is changed
            GUI.changed = true;

            // FIXME check for index out of bounds
            selectedMethod = new ComponentMethodInfo (_componentMethods [selected].Component, _componentMethods [selected]);

            if (_componentMethods.Count < 1) {
                string[] empty = {""};
                selected = EditorGUILayout.Popup (label, 0, empty);
            } else {
                selected = EditorGUILayout.Popup (label, selected, _names.ToArray ());
            }

            return selected;

            // FIXME if the array of available methods has changed (such as by adding or removing a method in a script,
            // try to re-connect to the previously held method regardless of the popup's current index.
            // FIXME provide an option for "none" at the end of the methods list
        }
Example #3
0
        public static object MethodParameterField(string label, ComponentMethodInfo method)
        {
            // Bail out if we have no parameters to configure. This will remove the parameter field entirely from the GUI.
            if (method == null)
                return null;
            else if (!method.HasParameter)
                return null;

            if (method.Parameter.ValueType == typeof(float))
                return EditorGUILayout.FloatField(label, method.Parameter.Value == null ? 0f : (float)method.Parameter.Value);
            if (method.Parameter.ValueType == typeof(int))
                return EditorGUILayout.IntField(label, method.Parameter.Value == null ? 0 : (int)method.Parameter.Value);
            if (method.Parameter.ValueType == typeof(string))
                return EditorGUILayout.TextField(label, method.Parameter.Value == null ? "" : (string)method.Parameter.Value);
            if (method.Parameter.ValueType == typeof(UnityEngine.Object))
                return EditorGUILayout.ObjectField(label, method.Parameter.Value == null ? null : (UnityEngine.Object)method.Parameter.Value, typeof(UnityEngine.Object), true);

            return null;
        }
 public ComponentMethodInfo(ComponentInfo component, ComponentMethodInfo method)
     : this(component, method.RawMethod)
 {
 }