//-------------------------------------------------------------------------------
    private void MethodGUI(ComponentMethod lMethod)
    {
        EditorGUI.indentLevel = 1;
        EditorGUILayout.BeginHorizontal();
        lMethod.m_Show = EditorGUILayout.Foldout(lMethod.m_Show, lMethod.m_MethodName);
        if (GUILayout.Button("Execute"))
        {
            object[] lParameters = new object[lMethod.m_ParameterArray.Length];
            for (int lCount = 0; lCount < lMethod.m_ParameterArray.Length; ++lCount)
            {
                lParameters[lCount] = lMethod.m_ParameterArray[lCount].m_ParameterInstance;
            }
            try
            {
                for (int lCount = 0; lCount < lMethod.m_Parent.m_Instances.Length; ++lCount)
                {
                    object lObject = lMethod.m_MethodInfo.Invoke(lMethod.m_Parent.m_Instances[lCount], lParameters);
                    if (lObject != null)
                    {
                        Debug.Log("Invoker: " + lMethod.m_MethodName + " returned " + lObject.ToString());
                    }
                }
            }
            catch
            {
                //Debug.Log("Invoker: " + lMethod.m_MethodName + " returned " + lObject.ToString());
            }
        }
        EditorGUILayout.EndHorizontal();

        if (lMethod.m_Show)
        {
            EditorGUILayout.Space();
            if (lMethod.m_ParameterArray.Length > 0)
            {
                foreach (ComponentParameter lParameter in lMethod.m_ParameterArray)
                {
                    ParameterGUI(lParameter);
                }
            }
            else
            {
                EditorGUI.indentLevel = 2;
                EditorGUILayout.LabelField("No Parameters");
            }
        }
        EditorGUILayout.Space();
    }
示例#2
0
    void UpdateMethodList()
    {
        byObject.Clear();
        byMethod.Clear();

        foreach (GameObject go in FindObjectsOfType(typeof(GameObject)) as GameObject[])
        {
            foreach (Component c in go.GetComponents <Component>())
            {
                if (c != null)
                {
                    foreach (MethodInfo m in c.GetType().GetMethods())
                    {
                        if (m.Name.StartsWith("Console_"))
                        {
                            ComponentMethod cm       = new ComponentMethod(c, m);
                            string          mod_name = m.Name.Replace("Console_", "");

                            // Add method to objects list of methods.
                            if (!byObject.ContainsKey(go.name))
                            {
                                byObject.Add(go.name, new Dictionary <string, ComponentMethod>());
                            }

                            if (!byObject[go.name].ContainsKey(mod_name))
                            {
                                byObject[go.name].Add(mod_name, cm);
                            }

                            // Add object to methods list of objects.
                            if (!byMethod.ContainsKey(mod_name))
                            {
                                byMethod.Add(mod_name, new List <ComponentMethod>());
                            }

                            byMethod[mod_name].Add(cm);

                            break;
                        }
                    }
                }
            }
        }
    }