示例#1
0
        Component[] GetAttackMethodComponents(GameObject fsmGO)
        {
            Component[]      components    = AIBehaviorsComponentInfoHelper.GetNonFSMComponents(fsmGO);
            List <Component> componentList = new List <Component>();

            foreach (Component component in components)
            {
                if (GetAttackMethodNamesForComponent(component).Length > 0)
                {
                    componentList.Add(component);
                }
            }

            return(componentList.ToArray());
        }
示例#2
0
        protected void GetScriptsToCall(SerializedObject m_State, AIBehaviors fsm)
        {
            Component[]   components         = AIBehaviorsComponentInfoHelper.GetNonFSMComponents(fsm.gameObject);
            List <string> includedComponents = new List <string>();
            Dictionary <Component, List <string> > methodsPerComponent = new Dictionary <Component, List <string> >();
            int                selectedComponent     = 0;
            string             selectedComponentType = "";
            SerializedProperty m_Property;

            if (defensiveCallScript != null)
            {
                selectedComponentType = defensiveCallScript.GetType().ToString();
            }

            foreach (Component component in components)
            {
                MethodInfo[] methods = component.GetType().GetMethods();

                foreach (MethodInfo method in methods)
                {
                    ParameterInfo[] parameters = method.GetParameters();

                    if (parameters.Length == 1)
                    {
                        if (parameters[0].ParameterType == this.GetType())
                        {
                            if (!methodsPerComponent.ContainsKey(component))
                            {
                                string componentType = component.GetType().Name;

                                includedComponents.Add(componentType);
                                methodsPerComponent[component] = new List <string>();

                                if (selectedComponentType == componentType)
                                {
                                    selectedComponent = includedComponents.Count - 1;
                                }
                            }

                            methodsPerComponent[component].Add(method.Name);
                        }
                    }
                }
            }

            if (includedComponents.Count > 0)
            {
                Component component = null;
                int       newIndex  = 0;

                EditorGUILayout.Separator();
                GUILayout.Label("Callback Properties:", EditorStyles.boldLabel);

                newIndex = EditorGUILayout.Popup("Defend callback script:", selectedComponent, includedComponents.ToArray());

                m_Property = m_State.FindProperty("defensiveCallScript");
                component  = fsm.gameObject.GetComponent(includedComponents[selectedComponent]);

                if (newIndex != selectedComponent || m_Property.objectReferenceValue == null)
                {
                    m_Property.objectReferenceValue = component as MonoBehaviour;
                }

                if (m_Property.objectReferenceValue != null)
                {
                    MethodInfo[] methods = m_Property.objectReferenceValue.GetType().GetMethods();

                    if (methods.Length > 0)
                    {
                        List <string> availableMethodsList = methodsPerComponent[component];
                        string[]      availableMethods     = availableMethodsList.ToArray();
                        int           startIndex           = 0;
                        int           endIndex             = 0;

                        // === Draw the start state method === //

                        m_Property = m_State.FindProperty("startDefendMethodName");
                        startIndex = availableMethodsList.IndexOf(m_Property.stringValue);

                        if (startIndex < 0)
                        {
                            startIndex = 0;
                        }

                        newIndex = EditorGUILayout.Popup("Start Defend callback:", startIndex, availableMethods);

                        if (newIndex != startIndex || m_Property.stringValue != availableMethods[newIndex])
                        {
                            m_Property.stringValue = availableMethods[newIndex];
                        }

                        // === Draw the end state method === //

                        m_Property = m_State.FindProperty("endDefendMethodName");
                        endIndex   = availableMethodsList.IndexOf(m_Property.stringValue);

                        if (endIndex < 0)
                        {
                            endIndex = 0;
                        }

                        newIndex = EditorGUILayout.Popup("Stop Defend callback:", endIndex, availableMethods);

                        if (newIndex != endIndex || m_Property.stringValue != availableMethods[newIndex])
                        {
                            m_Property.stringValue = availableMethods[newIndex];
                        }
                    }
                }
            }
            else
            {
                AIBehaviorsCodeSampleGUI.Draw(typeof(DefendState), "defendState", 2, new string[2] {
                    "OnStartDefending", "OnStopDefending"
                });
            }
        }