Beispiel #1
0
 public BlendPlayer(AnimationPlayer player, float blendSpeed)
 {
     this.player     = player;
     this.blendSpeed = blendSpeed;
     blend           = 0;
 }
Beispiel #2
0
        /// <summary>
        /// Play an animation clip
        /// </summary>
        /// <param name="clip">The clip to play</param>
        /// <returns>The player that will play this clip</returns>
        public AnimationPlayer PlayClip(AnimationClip clip, bool loop, float speed = 1f, float blendSpeed = 1f, float start = 1f / 24f)
        {
            bool newPlayer = true;

            if (blendSpeed >= 1)
            {
                //no blending
                players.Clear();
            }
            else
            {
                //blending
                if (blendSpeed < 0)
                {
                    blendSpeed = 0;
                }

                if (finalPlayer.Clip == clip && (finalPlayer.speed == 0) == (speed == 0))
                {
                    if (players.Count > 0)
                    {
                        players[players.Count - 1].blendSpeed = blendSpeed;
                    }
                    newPlayer = false;
                }

                //if the previous animation has the same clip as this new one (and both are animating or stopping), just swap finalPlayer with the last blendPlayer
                //else if (players.Count > 0 && players[players.Count - 1].player.Clip == clip && (players[players.Count - 1].player.speed == 0) == (speed == 0))
                //{
                //    BlendPlayer p = players[players.Count - 1];
                //    AnimationPlayer save = finalPlayer;
                //    finalPlayer = p.player;
                //    p.player = save;
                //    p.blend = 1 - p.blend;
                //    p.blendSpeed = blendSpeed;
                //}
                else
                {
                    //add blend player
                    players.Add(new BlendPlayer(finalPlayer, blendSpeed));
                }
            }

            if (newPlayer)
            {
                finalPlayer = new AnimationPlayer(clip, this, start);
            }
            finalPlayer.Looping = loop;
            finalPlayer.speed   = speed;


            return(finalPlayer);

            //// Create a clip player and assign it to this model

            //blendSpeed = Math.Max(0, Math.Min(1, blendSpeed));

            //this.blendSpeed = blendSpeed;

            //if (blendSpeed >= 1)
            //{
            //    player1 = new AnimationPlayer(clip, this, start);
            //    player1.Looping = loop;
            //    player1.speed = speed;
            //    clipBlend = 0;
            //    return player1;
            //}
            //else
            //{
            //    if (player2 != null)
            //    {
            //        if (player2.Clip == clip &&(player2.speed == 0) == (speed == 0)) //already blending to this clip
            //        { }
            //        else
            //        if (player1.Clip == clip) //reverse blending
            //        {
            //            //Swap players
            //            Calculate.Swap(ref player1, ref player2);
            //            clipBlend = 1 - clipBlend;
            //        }
            //        else
            //        {
            //            //jump to player2 if blending is >= 0.5
            //            if (clipBlend >= 0.5f)
            //                player1 = player2;
            //            player2 = null;
            //        }

            //    }

            //    if (player2 == null)
            //    {
            //        //(re)start blending
            //        player2 = new AnimationPlayer(clip, this, start);
            //        clipBlend = 0;
            //    }

            //    //set loop and speed
            //    player2.Looping = loop;
            //    player2.speed = speed;
            //    return player2;
            //}
        }