public static void DrawAnimProperties(AISkillState animState) { SerializedObject m_animState = new SerializedObject(animState); m_animState.Update(); SerializedProperty m_animName = m_animState.FindProperty("name"); SerializedProperty m_Id = m_animState.FindProperty("Id"); SerializedProperty m_Icon = m_animState.FindProperty("Icon"); SerializedProperty m_Desc = m_animState.FindProperty("Desc"); SerializedProperty m_currentCoolDown = m_animState.FindProperty("currentCoolDown"); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(m_animName); EditorGUILayout.PropertyField(m_Id); EditorGUILayout.PropertyField(m_Icon); EditorGUILayout.PropertyField(m_Desc); EditorGUILayout.PropertyField(m_currentCoolDown); EditorGUILayout.Separator(); m_animState.ApplyModifiedProperties(); }
protected override bool Evaluate(AIBehaviors fsm) { AISkillState state = fsm.skillStates.GetStateNoCoolingTime(); if (state != null) { return(true); } return(false); }
static int GetCurrentStateIndex(AISkillState curState, AISkillState[] states) { for (int i = 0; i < states.Length; i++) { if (curState == states[i]) { return(i); } } return(-1); }
protected override void Init(AIBehaviors fsm) { target = GetTarget(fsm); if (target != null) { AIBehaviors targetable = target.GetComponent <AIBehaviors>(); AISkillState aiSkillState = skillStatesComponent.GetStateNoCoolingTime(); Skill skillInfo = GameData.skills[aiSkillState.Id]; aiSkillState.currentCoolDown = skillInfo.CoolDown; SkillData skillData = new SkillData(fsm, targetable, skillInfo); fsm.PlaySkill(skillData); Debug.Log(fsm.name); fsm.ChangeActiveState(fsm.previousState); } else { fsm.ChangeActiveState(fsm.previousState); } }
public static void DrawAnimationFields(SerializedObject m_StateObject, bool usesMultipleAnimations) { SerializedProperty m_animationStates = m_StateObject.FindProperty("skillStatesComponent"); SerializedProperty statesProperty = m_StateObject.FindProperty("skillStates"); int arraySize = statesProperty.arraySize; AISkillStates animStatesComponent; AIBehaviorsStyles styles = new AIBehaviorsStyles(); bool newFoldoutValue; bool hadNullAnimation = false; const string foldoutValueKey = "AIBehaviors_SkillsFoldout"; AssignAnimationStatesComponent(m_StateObject); animStatesComponent = m_animationStates.objectReferenceValue as AISkillStates; if (!gotFoldoutValue) { if (EditorPrefs.HasKey(foldoutValueKey)) { foldoutValue = EditorPrefs.GetBool(foldoutValueKey); } gotFoldoutValue = true; } newFoldoutValue = foldoutValue; newFoldoutValue = EditorGUILayout.Foldout(foldoutValue, "Skills:", EditorStyles.foldoutPreDrop); if (foldoutValue != newFoldoutValue) { foldoutValue = newFoldoutValue; EditorPrefs.SetBool(foldoutValueKey, foldoutValue); } // Check the array for null animations for (int i = 0; i < arraySize; i++) { if (statesProperty.GetArrayElementAtIndex(i).objectReferenceValue == null) { if (animStatesComponent != null) { statesProperty.GetArrayElementAtIndex(i).objectReferenceValue = animStatesComponent.states[0]; hadNullAnimation = true; } } } if (!foldoutValue || hadNullAnimation) { m_StateObject.ApplyModifiedProperties(); return; } // Is the component assigned? if (m_animationStates.objectReferenceValue != null && animStatesComponent != null && arraySize > 0) { GUILayout.BeginVertical(GUI.skin.box); AISkillState[] states = new AISkillState[arraySize]; string[] animationStateNames = GetAnimationStateNames(m_StateObject); if (animStatesComponent.states.Length == 0) { Color oldColor = GUI.color; GUI.color = Color.yellow; GUILayout.Label("No states have been created\nfor the AISkillStates component."); GUI.color = oldColor; return; } for (int i = 0; i < arraySize; i++) { SerializedProperty prop = statesProperty.GetArrayElementAtIndex(i); bool oldEnabled = GUI.enabled; if (prop != null) { Object obj = prop.objectReferenceValue; int curIndex; if (obj != null) { states[i] = obj as AISkillState; curIndex = GetCurrentStateIndex(states[i], animStatesComponent.states); if (curIndex == -1) { if (animStatesComponent.states.Length > 0) { curIndex = 0; states[i] = animStatesComponent.states[0]; } } GUILayout.BeginHorizontal(); { curIndex = EditorGUILayout.Popup(curIndex, animationStateNames, EditorStyles.popup); m_StateObject.FindProperty(string.Format(kArrayData, i)).objectReferenceValue = animStatesComponent.states[curIndex]; if (usesMultipleAnimations) { GUI.enabled = i > 0; if (GUILayout.Button(styles.blankContent, styles.upStyle, GUILayout.MaxWidth(styles.arrowButtonWidths))) { statesProperty.MoveArrayElement(i, i - 1); } GUI.enabled = i < arraySize - 1; if (GUILayout.Button(styles.blankContent, styles.downStyle, GUILayout.MaxWidth(styles.arrowButtonWidths))) { statesProperty.MoveArrayElement(i, i + 1); } GUI.enabled = true; if (GUILayout.Button(styles.blankContent, styles.addStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths))) { statesProperty.InsertArrayElementAtIndex(i); } //GUI.enabled = arraySize > 1; if (GUILayout.Button(styles.blankContent, styles.removeStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths))) { AIBehaviorsAssignableObjectArray.RemoveObjectAtIndex(m_StateObject, i, "skillStates"); GUILayout.EndHorizontal(); break; } GUI.enabled = oldEnabled; } } GUILayout.EndHorizontal(); } else { statesProperty.GetArrayElementAtIndex(i).objectReferenceValue = animStatesComponent.states[0]; } } GUI.enabled = oldEnabled; } GUILayout.EndVertical(); } if (GUILayout.Button(styles.blankContent, styles.addStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths))) { statesProperty.arraySize++; statesProperty.GetArrayElementAtIndex(arraySize).objectReferenceValue = animStatesComponent.states[0]; } m_StateObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { m_Object.Update(); int arraySize = m_AnimationStatesCount.intValue; AISkillState[] states = new AISkillState[arraySize + 1]; for (int i = 0; i < arraySize; i++) { string stateNameLabel = ""; bool oldEnabled = GUI.enabled; if (m_Object.FindProperty(string.Format(kArrayData, i)) == null) { AIBehaviorsAssignableObjectArray.RemoveObjectAtIndex(m_Object, i, "states"); continue; } states[i] = m_Object.FindProperty(string.Format(kArrayData, i)).objectReferenceValue as AISkillState; if (states[i] == null) { AIBehaviorsAssignableObjectArray.RemoveObjectAtIndex(m_Object, i, "states"); continue; } GUILayout.BeginHorizontal(); if (string.IsNullOrEmpty(states[i].name)) { stateNameLabel = "Untitled skill"; } else { stateNameLabel = states[i].name; } states[i].foldoutOpen = EditorGUILayout.Foldout(states[i].foldoutOpen, stateNameLabel, EditorStyles.foldoutPreDrop); GUI.enabled = i > 0; if (GUILayout.Button(styles.blankContent, styles.upStyle, GUILayout.MaxWidth(styles.arrowButtonWidths))) { animationStatesProp.MoveArrayElement(i, i - 1); } GUI.enabled = i < arraySize - 1; if (GUILayout.Button(styles.blankContent, styles.downStyle, GUILayout.MaxWidth(styles.arrowButtonWidths))) { animationStatesProp.MoveArrayElement(i, i + 1); } GUI.enabled = true; if (GUILayout.Button(styles.blankContent, styles.addStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths))) { animationStatesProp.InsertArrayElementAtIndex(i); animationStatesProp.GetArrayElementAtIndex(i + 1).objectReferenceValue = statesGameObject.AddComponent <AISkillState>(); } GUI.enabled = arraySize > 1; if (GUILayout.Button(styles.blankContent, styles.removeStyle, GUILayout.MaxWidth(styles.addRemoveButtonWidths))) { AIBehaviorsAssignableObjectArray.RemoveObjectAtIndex(m_Object, i, "states"); DestroyImmediate(m_Object.targetObject as AISkillState); break; } GUI.enabled = oldEnabled; GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.Space(2); if (states[i].foldoutOpen) { DrawAnimProperties(states[i]); } else { SerializedObject serializedAnimState = new SerializedObject(states[i]); serializedAnimState.ApplyModifiedProperties(); } } if (arraySize == 0) { m_Object.FindProperty(kArraySize).intValue++; animationStatesProp.GetArrayElementAtIndex(0).objectReferenceValue = statesGameObject.AddComponent <AISkillState>(); } EditorGUILayout.Separator(); m_Object.ApplyModifiedProperties(); }