Exemple #1
0
 protected void RemoveAllAndAddCondition(AnimatorTransitionBase transition, string paramName, AnimatorConditionMode mode, float threshold)
 {
     foreach (AnimatorCondition condition in transition.conditions)
     {
         if (condition.parameter == paramName)
         {
             transition.RemoveCondition(condition);
         }
     }
     transition.AddCondition(mode, threshold, paramName);
 }
Exemple #2
0
        private void DrawAnimatorTransition(AnimatorTransitionBase transition, string source = null, CombinedAnimatorState sourceState = null, bool foldout = true)
        {
            // This is ugly. Apparently you can't modify the collection directly.
            // The only way I found that worked was to remove conditions and readd
            // on modification. There must be a better way to do it.
            // TODO: Do this the right way.
            List <AnimatorCondition> conditions = new List <AnimatorCondition>();
            bool modified = false;

            string label = GetTransitionLabel(transition, sourceState, source);

            GUILayout.BeginHorizontal();
            {
                if (foldout)
                {
                    foldouts[transition] = EditorGUILayout.Foldout(CollectionUtil.GetOrAdd(foldouts, transition, false), label);
                }
                else
                {
                    GUILayout.Label(label);
                }
                if (!foldout || foldouts[transition])
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("+", InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16), GUILayout.Height(16)))
                    {
                        AnimatorCondition condition = new AnimatorCondition();
                        condition.parameter = parameterNames[0];
                        conditions.Add(condition);
                        modified = true;
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (!foldout || foldouts[transition])
            {
                for (int i = 0; i < transition.conditions.Length; i++)
                {
                    var  condition = transition.conditions[i];
                    bool remove;
                    if (DrawAnimatorCondition(ref condition, out remove))
                    {
                        if (!remove)
                        {
                            conditions.Add(condition);
                        }
                        modified = true;
                    }
                    else
                    {
                        conditions.Add(transition.conditions[i]);
                    }
                }

                if (modified)
                {
                    while (transition.conditions.Length > 0)
                    {
                        transition.RemoveCondition(transition.conditions[0]);
                    }

                    foreach (AnimatorCondition condition in conditions)
                    {
                        transition.AddCondition(condition.mode, condition.threshold, condition.parameter);
                    }
                }
            }
        }