protected override void DrawStateInspectorEditor(SerializedObject m_State, AIBehaviors fsm) { SerializedProperty m_property; string[] animNames = AIBehaviorsAnimationEditorGUI.GetAnimationStateNames(m_State); int curAttackAnimIndex = 0; for (int i = 0; i < animNames.Length; i++) { if (animNames[i] == animationStates[0].name) { curAttackAnimIndex = i; } } GUILayout.Label("Attack Properties:", EditorStyles.boldLabel); GUILayout.BeginVertical(GUI.skin.box); m_property = m_State.FindProperty("attackDamage"); EditorGUILayout.PropertyField(m_property); EditorGUILayout.Separator(); // Movement Settings GUILayout.Label("Movement Settings:", EditorStyles.boldLabel); m_property = m_State.FindProperty("inheritPreviousStateMovement"); EditorGUILayout.PropertyField(m_property); EditorGUILayout.Separator(); // Animation Settings GUILayout.Label("Animation Settings:", EditorStyles.boldLabel); m_property = m_State.FindProperty("attackPoint"); EditorGUILayout.Slider(m_property, 0.0f, 1.0f); if (!Application.isPlaying) { if (curAttackAnimIndex != -1 && curAttackAnimIndex < animNames.Length) { float calcAttackTime = SampleAttackAnimation(fsm, animNames[curAttackAnimIndex], m_property.floatValue); m_property = m_State.FindProperty("animAttackTime"); m_property.floatValue = calcAttackTime; } } EditorGUILayout.Separator(); // === Reload Properties === // GUILayout.Label("Reload Settings:", EditorStyles.boldLabel); m_property = m_State.FindProperty("attacksBeforeReload"); EditorGUILayout.PropertyField(m_property, new GUIContent("Attacks Before Reload")); m_property = m_State.FindProperty("attackCount"); EditorGUILayout.PropertyField(m_property, new GUIContent("Attack count (of " + attacksBeforeReload + ")")); GUILayout.BeginHorizontal(); { GUILayout.Label("Reload State:"); m_property = m_State.FindProperty("reloadState"); m_property.objectReferenceValue = AIBehaviorsStatePopups.DrawEnabledStatePopup(fsm, m_property.objectReferenceValue as BaseState); if (reloadState == null) { m_property.objectReferenceValue = this; } } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); // === Attack Method === // GUILayout.Label("Attack Method:", EditorStyles.boldLabel); Component[] components = GetAttackMethodComponents(fsm.gameObject); int selectedComponent = -1, newSelectedComponent = 0; if (components.Length > 0) { string[] componentNames = GetAttackMethodComponentNames(components); for (int i = 0; i < components.Length; i++) { if (components[i] == scriptWithAttackMethod) { selectedComponent = i; break; } } newSelectedComponent = EditorGUILayout.Popup(selectedComponent, componentNames); if (selectedComponent != newSelectedComponent) { m_property = m_State.FindProperty("scriptWithAttackMethod"); m_property.objectReferenceValue = components[newSelectedComponent]; } } else { AIBehaviorsCodeSampleGUI.Draw(typeof(AttackData), "attackData", "OnAttack"); } if (components.Length > 0) { string[] methodNames = GetAttackMethodNamesForComponent(components[selectedComponent < 0 ? 0 : selectedComponent]); int curSelectedMethod = -1, newSelectedMethod = 0; for (int i = 0; i < methodNames.Length; i++) { if (methodNames[i] == methodName) { curSelectedMethod = i; break; } } newSelectedMethod = EditorGUILayout.Popup(curSelectedMethod, methodNames); if (curSelectedMethod != newSelectedMethod) { m_property = m_State.FindProperty("methodName"); m_property.stringValue = methodNames[newSelectedMethod]; } } GUILayout.EndVertical(); m_State.ApplyModifiedProperties(); }
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" }); } }