public void MoveConditionDown(AT_TransitionCondition condition)
 {
     int index = m_conditions.IndexOf (condition);
     index = Mathf.Clamp (index + 1, 0, m_conditions.Count - 1);
     m_conditions.Remove (condition);
     m_conditions.Insert (index, condition);
 }
 public void ReplaceCondition(AT_TransitionCondition oldCond, AT_TransitionCondition newCond)
 {
     int index = m_conditions.IndexOf(oldCond);
     m_conditions.Insert(index, newCond);
     RemoveCondition(oldCond);
 }
 // Functions mostly used by editor to add/remove or change certain conditions
 public void AddCondition( AT_TransitionCondition condition )
 {
     m_conditions.Add(condition);
 }
 public void RemoveCondition(AT_TransitionCondition condition)
 {
     m_conditions.Remove (condition);
 }
    string GetTitleForCondition(AT_TransitionCondition cond)
    {
        if (cond != null)
        {
            switch (cond.m_conditionType)
            {
                case AT_TransitionCondition.ConditionType.kRequest:
                    return "Request Condition";

                case AT_TransitionCondition.ConditionType.kProbability:
                    return "Probability Condition";

                case AT_TransitionCondition.ConditionType.kTimed:
                    return "Timed Condition";

                case AT_TransitionCondition.ConditionType.kMath:
                    return "Math Condition";

                case AT_TransitionCondition.ConditionType.kAnimationLoop:
                    return "Animation Loop Condition";
            }
        }

        return "Unknown Condition";
    }
    void DrawConditionGUI(AT_TransitionCondition cond)
    {
        if (cond == null)
        {
            return;
        }

        EditorGUILayout.BeginHorizontal ();
        GUILayout.Space (EditorGUI.indentLevel * 12);
        m_conditionDetails[m_conditionCounter] = EditorGUILayout.Foldout (m_conditionDetails[m_conditionCounter], GetTitleForCondition (cond));

        // Move Condition Up
        if (GUILayout.Button ("^", GUILayout.MaxWidth (20), GUILayout.MaxHeight (15)))
        {
            m_conditionsToMoveUp.Add (cond);
        }

        // Move Condition Down
        if (GUILayout.Button ("v", GUILayout.MaxWidth (20), GUILayout.MaxHeight (15)))
        {
            m_conditionsToMoveDown.Add (cond);
        }

        // Delete button
        if (GUILayout.Button ("-", GUILayout.MaxWidth (20), GUILayout.MaxHeight (15)))
        {
            m_conditionsToRemove.Add (cond);
        }
        EditorGUILayout.EndHorizontal ();

        if (m_conditionDetails[m_conditionCounter])
        {
            EditorGUILayout.Space ();

            EditorGUI.indentLevel++;

            EditorGUILayout.BeginHorizontal ();

            // Indent space
            EditorGUILayout.BeginVertical (GUILayout.MaxWidth (EditorGUI.indentLevel * 8));
            EditorGUILayout.Space ();
            EditorGUILayout.EndVertical ();

            EditorGUILayout.BeginVertical ();

            AT_TransitionCondition.ConditionType type = (AT_TransitionCondition.ConditionType)EditorGUILayout.EnumPopup ("Type", cond.m_conditionType, GUILayout.ExpandWidth (true));
            if (type != cond.m_conditionType)
            {
                // Change condition type
                ChangeConditionType (cond, type);
            }

            EditorGUILayout.Separator ();

            switch (cond.m_conditionType)
            {
            case AT_TransitionCondition.ConditionType.kRequest:
                DrawRequestCondition (cond as AT_RequestCondition);
                break;

                case AT_TransitionCondition.ConditionType.kProbability:
                DrawProbabilityCondition (cond as AT_ProbabilityCondition);
                break;

                case AT_TransitionCondition.ConditionType.kTimed:
                DrawTimedCondition (cond as AT_TimedCondition);
                break;

                case AT_TransitionCondition.ConditionType.kMath:
                DrawMathCondition (cond as AT_MathCondition);
                break;

                case AT_TransitionCondition.ConditionType.kAnimationLoop:
                DrawAnimationLoopCondition (cond as AT_AnimLoopCondition);
                break;

                default:
                EditorGUILayout.PrefixLabel ("Unknown");
                break;
            }

            //EditorGUILayout.EndVertical ();

            cond.m_resetWhenFromStateNotCurrent = GUILayout.Toggle (cond.m_resetWhenFromStateNotCurrent, "Reset when 'from' state is not current", GUILayout.ExpandWidth (true));
            //EditorGUILayout.BeginVertical (GUILayout.MaxWidth (EditorGUI.indentLevel * 8));
            GUILayout.Toggle (cond.IsConditionMet (), "Met", GUILayout.ExpandWidth (true));
            EditorGUILayout.EndVertical ();

            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.Separator ();

            EditorGUI.indentLevel--;
        }
    }
    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;
    }
    void ChangeConditionType(AT_TransitionCondition cond, AT_TransitionCondition.ConditionType newType)
    {
        AT_TransitionCondition newCond = CreateConditionOfType (newType, m_transition);

        m_transition.ReplaceCondition (cond, newCond);

        GameObject.DestroyImmediate (cond.gameObject);
    }