public TransitionWindow( AT_StateTransition trans ) { m_transistionNode = trans; TreeNode = trans; }
// Delete a transition public void RemoveTransition( AT_StateTransition trans ) { m_transitions.Remove(trans); }
AT_TransitionCondition CreateConditionOfType(AT_TransitionCondition.ConditionType newType, AT_StateTransition trans) { AT_TransitionCondition cond = null; GameObject go = new GameObject ("Condition"); go.transform.parent = trans.transform; switch (newType) { case AT_TransitionCondition.ConditionType.kProbability: cond = go.AddComponent<AT_ProbabilityCondition> (); break; case AT_TransitionCondition.ConditionType.kRequest: cond = go.AddComponent<AT_RequestCondition> (); break; case AT_TransitionCondition.ConditionType.kTimed: cond = go.AddComponent<AT_TimedCondition> (); break; case AT_TransitionCondition.ConditionType.kMath: cond = go.AddComponent<AT_MathCondition> (); break; case AT_TransitionCondition.ConditionType.kAnimationLoop: cond = go.AddComponent<AT_AnimLoopCondition> (); break; } return cond; }
public override void OnInspectorGUI() { EditorGUILayout.Separator (); EditorGUIUtility.LookLikeControls (); EditorGUI.indentLevel = 1; m_transition = target as AT_StateTransition; AT_StateMachine sm = m_transition.Parent as AT_StateMachine; List<AT_State> states = new List<AT_State> (); string[] options = { "" }; // Compile list of states if (sm != null) { foreach (AT_Node node in sm.Children) { AT_State state = node as AT_State; if (state != null) { states.Add (state); } } foreach (AT_Node node in sm.UnassignedChildren) { AT_State state = node as AT_State; if (state != null) { states.Add (state); } } } // fill up the popup options options = new string[states.Count]; int counter = 0; int fromSelectedOption = 0; int toSelectedOption = 0; foreach (AT_State state in states) { options[counter] = state.m_stateName; if (state == m_transition.m_fromState) { fromSelectedOption = counter; } if (state == m_transition.m_toState) { toSelectedOption = counter; } counter++; } // Draw the state popups int newFromSelection = EditorGUILayout.Popup ("From State", fromSelectedOption, options, GUILayout.ExpandWidth (true)); if (states.Count - 1 >= newFromSelection) { m_transition.m_fromState = states[newFromSelection]; AnimationTreeEditor.instance.RebuildTreeGraph (); } int newToSelection = EditorGUILayout.Popup ("To State", toSelectedOption, options, GUILayout.ExpandWidth (true)); if (states.Count - 1 >= newToSelection) { m_transition.m_toState = states[newToSelection]; AnimationTreeEditor.instance.RebuildTreeGraph (); } EditorGUILayout.Separator (); // Draw the transition time m_transition.m_transitionTime = Mathf.Max (0, EditorGUILayout.FloatField ("Transition Time", m_transition.m_transitionTime, GUILayout.ExpandWidth (true))); EditorGUILayout.Separator (); bool reinit = false; if ( m_transition.m_conditions != null ) { if (m_conditionDetails.Count != m_transition.m_conditions.Count) { reinit = true; } // Draw conditions m_conditionsToRemove.Clear (); m_conditionsToMoveUp.Clear (); m_conditionsToMoveDown.Clear (); m_conditionCounter = 0; m_conditionsFoldout = EditorGUILayout.Foldout (m_conditionsFoldout, "Conditions"); AT_TransitionCondition[] tempList = m_transition.m_conditions.ToArray (); if (m_conditionsFoldout) { foreach (AT_TransitionCondition cond in tempList) { if (reinit) { m_conditionDetails.Add (true); } DrawConditionGUI (cond); m_conditionCounter++; } EditorGUILayout.Space (); EditorGUILayout.BeginHorizontal (); EditorGUI.indentLevel++; GUILayout.Space (EditorGUI.indentLevel * 12); if (GUILayout.Button ("Add Condition", GUILayout.MaxWidth (100))) { AddNewCondition (m_transition); } EditorGUI.indentLevel--; EditorGUILayout.EndHorizontal (); } // Remove deleted conditions foreach (AT_TransitionCondition cond in m_conditionsToRemove) { m_transition.RemoveCondition (cond); GameObject.DestroyImmediate (cond.gameObject); } foreach (AT_TransitionCondition cond in m_conditionsToMoveUp) { m_transition.MoveConditionUp (cond); } foreach (AT_TransitionCondition cond in m_conditionsToMoveDown) { m_transition.MoveConditionDown (cond); } } EditorGUILayout.Space (); if ( m_transition != null ) { EditorGUI.indentLevel++; m_transition.fireRequestOnTransitionStart = EditorGUILayout.BeginToggleGroup("Fire Request On Transition Start", m_transition.fireRequestOnTransitionStart); if ( m_transition.fireRequestOnTransitionStart ) { EditorGUI.indentLevel++; m_transition.transitionStartRequest = EditorGUILayout.TextField("Start Request", m_transition.transitionStartRequest, GUILayout.ExpandWidth(true)); EditorGUI.indentLevel--; } EditorGUILayout.EndToggleGroup(); m_transition.fireRequestOnTransitionEnd = EditorGUILayout.BeginToggleGroup("Fire Request On Transition End", m_transition.fireRequestOnTransitionEnd); if ( m_transition.fireRequestOnTransitionEnd) { EditorGUI.indentLevel++; m_transition.transitionEndRequest = EditorGUILayout.TextField("End Request", m_transition.transitionEndRequest, GUILayout.ExpandWidth(true)); EditorGUI.indentLevel--; } EditorGUILayout.EndToggleGroup(); EditorGUI.indentLevel--; } base.OnInspectorGUI(); }
void AddNewCondition(AT_StateTransition trans) { AT_TransitionCondition cond = CreateConditionOfType (AT_TransitionCondition.ConditionType.kRequest, trans);//ScriptableObject.CreateInstance<AT_RequestCondition>(); trans.AddCondition(cond); }