Exemplo n.º 1
0
    AnimatorStateTransition[] ProcessTransitions(AnimatorStateTransition[] transitions)
    {
        List <AnimatorStateTransition> transitionsToAdd = new List <AnimatorStateTransition>();

        for (int t = 0; t < transitions.Length; t++)
        {
            List <AnimatorCondition> conditionsToAdd = new List <AnimatorCondition>();

            // Debug.Log(transitions[t].conditions.Length + " conditions");

            for (int c = 0; c < transitions[t].conditions.Length; c++)
            {
                AnimatorCondition condition = transitions[t].conditions[c];

                // Debug.Log("CHECK " + condition.parameter + " " + condition.mode + " " + condition.threshold);

                // TODO: Use switch
                if (condition.mode == AnimatorConditionMode.Equals)
                {
                    if (condition.parameter == "GestureLeft" || condition.parameter == "GestureRight")
                    {
                        float chilloutGestureNumber = GetChilloutGestureNumberForVrchatGestureNumber(condition.threshold);

                        AnimatorCondition newConditionLessThan = new AnimatorCondition();
                        newConditionLessThan.parameter = condition.parameter;
                        newConditionLessThan.mode      = AnimatorConditionMode.Less;
                        newConditionLessThan.threshold = (float)(chilloutGestureNumber + 0.1);

                        conditionsToAdd.Add(newConditionLessThan);

                        AnimatorCondition newConditionGreaterThan = new AnimatorCondition();
                        newConditionGreaterThan.parameter = condition.parameter;
                        newConditionGreaterThan.mode      = AnimatorConditionMode.Greater;
                        newConditionGreaterThan.threshold = (float)(chilloutGestureNumber - 0.1);

                        conditionsToAdd.Add(newConditionGreaterThan);
                    }
                    else
                    {
                        AnimatorCondition newConditionLessThan = new AnimatorCondition();
                        newConditionLessThan.parameter = condition.parameter;
                        newConditionLessThan.mode      = AnimatorConditionMode.Less;
                        newConditionLessThan.threshold = (float)(condition.threshold + 0.1);

                        conditionsToAdd.Add(newConditionLessThan);

                        AnimatorCondition newConditionGreaterThan = new AnimatorCondition();
                        newConditionGreaterThan.parameter = condition.parameter;
                        newConditionGreaterThan.mode      = AnimatorConditionMode.Greater;
                        newConditionGreaterThan.threshold = (float)(condition.threshold - 0.1);

                        conditionsToAdd.Add(newConditionGreaterThan);
                    }
                }
                else if (condition.mode == AnimatorConditionMode.NotEqual)
                {
                    if (condition.parameter == "GestureLeft" || condition.parameter == "GestureRight")
                    {
                        float chilloutGestureNumber = GetChilloutGestureNumberForVrchatGestureNumber(condition.threshold);

                        AnimatorCondition newConditionLessThan = new AnimatorCondition();
                        newConditionLessThan.parameter = condition.parameter;
                        newConditionLessThan.mode      = AnimatorConditionMode.Less;
                        newConditionLessThan.threshold = (float)(chilloutGestureNumber - 0.1);

                        conditionsToAdd.Add(newConditionLessThan);
                    }
                    else
                    {
                        AnimatorCondition newConditionLessThan = new AnimatorCondition();
                        newConditionLessThan.parameter = condition.parameter;
                        newConditionLessThan.mode      = AnimatorConditionMode.Less;
                        newConditionLessThan.threshold = (float)(condition.threshold - 0.1);

                        conditionsToAdd.Add(newConditionLessThan);

                        AnimatorStateTransition newTransition = AnimatorStateTransition.Instantiate(transitions[t]);
                        newTransition.conditions = new AnimatorCondition[] {
                            new AnimatorCondition()
                            {
                                parameter = condition.parameter,
                                mode      = AnimatorConditionMode.Greater,
                                threshold = (float)(condition.threshold + 0.1)
                            }
                        };

                        transitionsToAdd.Add(newTransition);
                    }
                }
                else if (condition.mode == AnimatorConditionMode.If)
                {
                    AnimatorCondition newConditionLessThan = new AnimatorCondition();
                    newConditionLessThan.parameter = condition.parameter;
                    newConditionLessThan.mode      = AnimatorConditionMode.Less;
                    newConditionLessThan.threshold = (float)1.1;

                    conditionsToAdd.Add(newConditionLessThan);

                    AnimatorCondition newConditionGreaterThan = new AnimatorCondition();
                    newConditionGreaterThan.parameter = condition.parameter;
                    newConditionGreaterThan.mode      = AnimatorConditionMode.Greater;
                    newConditionGreaterThan.threshold = (float)0.5;

                    conditionsToAdd.Add(newConditionGreaterThan);
                }
                else if (condition.mode == AnimatorConditionMode.IfNot)
                {
                    AnimatorCondition newConditionLessThan = new AnimatorCondition();
                    newConditionLessThan.parameter = condition.parameter;
                    newConditionLessThan.mode      = AnimatorConditionMode.Less;
                    newConditionLessThan.threshold = (float)0.49;

                    conditionsToAdd.Add(newConditionLessThan);

                    AnimatorCondition newConditionGreaterThan = new AnimatorCondition();
                    newConditionGreaterThan.parameter = condition.parameter;
                    newConditionGreaterThan.mode      = AnimatorConditionMode.Greater;
                    newConditionGreaterThan.threshold = (float)-0.1;

                    conditionsToAdd.Add(newConditionGreaterThan);
                }
                else if (condition.mode == AnimatorConditionMode.Greater)
                {
                    AnimatorCondition newCondition = new AnimatorCondition();
                    newCondition.parameter = condition.parameter;
                    newCondition.mode      = AnimatorConditionMode.Greater;
                    newCondition.threshold = condition.threshold;

                    conditionsToAdd.Add(newCondition);
                }
                else if (condition.mode == AnimatorConditionMode.Less)
                {
                    AnimatorCondition newCondition = new AnimatorCondition();
                    newCondition.parameter = condition.parameter;
                    newCondition.mode      = AnimatorConditionMode.Less;
                    newCondition.threshold = condition.threshold;

                    conditionsToAdd.Add(newCondition);
                }
            }

            transitions[t].conditions = conditionsToAdd.ToArray();
        }

        AnimatorStateTransition[] newTransitions = new AnimatorStateTransition[transitions.Length + transitionsToAdd.Count];

        transitions.CopyTo(newTransitions, 0);
        transitionsToAdd.ToArray().CopyTo(newTransitions, transitions.Length);

        return(newTransitions);
    }