Exemplo n.º 1
0
        public AnimationStateMachine(AnimationPackage package)
        {
            horizMovement = Vector2.Zero;
            mSkinningData = package.SkinningData;

            // Use the data in the AnimationPackage structure to create states to fill our list and build
            // a transition matrix.

            states = new Dictionary <string, AnimationState>();
            foreach (AnimationStateDescription stateDesc in package.StateDescriptions)
            {
                AnimationState newState = new AnimationState(stateDesc, package);
                states.Add(newState.Name, newState);
            }

            transitions = new Dictionary <AnimationState, Dictionary <AnimationState, TransitionInfo> >();

            foreach (KeyValuePair <string, AnimationState> currentStateKvp in states)
            {
                transitions.Add(currentStateKvp.Value, new Dictionary <AnimationState, TransitionInfo>());

                foreach (KeyValuePair <string, AnimationState> nextStateKvp in states)
                {
                    TransitionInfo bestFitTransition = null;

                    foreach (TransitionInfo ti in package.Transitions)
                    {
                        // The items lower in the list are higher priority and will override previous matches.
                        if (ti.IsMatch(currentStateKvp.Key, nextStateKvp.Key))
                        {
                            bestFitTransition = ti;
                        }
                    }

                    transitions[currentStateKvp.Value].Add(nextStateKvp.Value, bestFitTransition);
                }
            }

            CurrentState     = states[package.InitialStateName];
            desiredState     = CurrentState;
            ActiveTransition = null;
            nextState        = null;
            blendFromCancelledTransitionPose = false;
            ActiveControlEvents = AnimationControlEvents.None;
        }
Exemplo n.º 2
0
 private void UpdateTransition()
 {
     // Find the appropriate transition info and assign it here.
     if (nextState != null)
     {
         if (blendFromCancelledTransitionPose)
         {
             TransitionInfo cancelTransition = new TransitionInfo();
             cancelTransition.DurationInSeconds = 0.2f;
             cancelTransition.Type          = TransitionType.Frozen;
             cancelTransition.UseSmoothStep = true;
             ActiveTransition = cancelTransition;
         }
         else
         {
             ActiveTransition = transitions[CurrentState][nextState];
         }
         transitionTime = TimeSpan.Zero;
     }
     else
     {
         ActiveTransition = null;
     }
 }
Exemplo n.º 3
0
        public AnimationStateMachine(AnimationPackage package)
        {
            horizMovement = Vector2.Zero;
            mSkinningData = package.SkinningData;

            // Use the data in the AnimationPackage structure to create states to fill our list and build
            // a transition matrix.

            states = new Dictionary<string, AnimationState>();
            foreach (AnimationStateDescription stateDesc in package.StateDescriptions)
            {
                AnimationState newState = new AnimationState(stateDesc, package);
                states.Add(newState.Name, newState);
            }

            transitions = new Dictionary<AnimationState, Dictionary<AnimationState, TransitionInfo>>();

            foreach (KeyValuePair<string, AnimationState> currentStateKvp in states)
            {
                transitions.Add(currentStateKvp.Value, new Dictionary<AnimationState, TransitionInfo>());

                foreach (KeyValuePair<string, AnimationState> nextStateKvp in states)
                {
                    TransitionInfo bestFitTransition = null;

                    foreach (TransitionInfo ti in package.Transitions)
                    {
                        // The items lower in the list are higher priority and will override previous matches.
                        if (ti.IsMatch(currentStateKvp.Key, nextStateKvp.Key))
                            bestFitTransition = ti;
                    }

                    transitions[currentStateKvp.Value].Add(nextStateKvp.Value, bestFitTransition);
                }
            }

            CurrentState = states[package.InitialStateName];
            desiredState = CurrentState;
            ActiveTransition = null;
            nextState = null;
            blendFromCancelledTransitionPose = false;
            ActiveControlEvents = AnimationControlEvents.None;
        }
Exemplo n.º 4
0
 private void UpdateTransition()
 {
     // Find the appropriate transition info and assign it here.
     if (nextState != null)
     {
         if (blendFromCancelledTransitionPose)
         {
             TransitionInfo cancelTransition = new TransitionInfo();
             cancelTransition.DurationInSeconds = 0.2f;
             cancelTransition.Type = TransitionType.Frozen;
             cancelTransition.UseSmoothStep = true;
             ActiveTransition = cancelTransition;
         }
         else
         {
             ActiveTransition = transitions[CurrentState][nextState];
         }
         transitionTime = TimeSpan.Zero;
     }
     else
     {
         ActiveTransition = null;
     }
 }