/// <summary>
        /// Play an animation clip
        /// </summary>
        /// <param name="clip">The clip to play</param>
        /// <returns>The player that will play this clip</returns>
        private void PlayAnimation(MyAnimationDefinition animationDefinition, bool loop, float blendTime, float timeScale, MyPlayAnimationMode mode)
        {
            string model = animationDefinition.AnimationModel;
            int clipIndex = animationDefinition.ClipIndex;

            if (string.IsNullOrEmpty(model))
                return;

            if (animationDefinition.Status == MyAnimationDefinition.AnimationStatus.Unchecked)
            {
                var fsPath = System.IO.Path.IsPathRooted(model) ? model : System.IO.Path.Combine(MyFileSystem.ContentPath, model);
                if (!MyFileSystem.FileExists(fsPath))
                {
                    animationDefinition.Status = MyAnimationDefinition.AnimationStatus.Failed;
                    return;
                }
            }

            animationDefinition.Status = MyAnimationDefinition.AnimationStatus.OK;

            MyModel animation = MyModels.GetModelOnlyAnimationData(model);
            AnimationClip clip = animation.Animations.Clips[clipIndex];

            // Create a clip player and assign it to this model
            m_playerNextAnim.Initialize(clip, this, 1, timeScale, mode == MyPlayAnimationMode.JustFirstFrame);
            m_playerNextAnim.Looping = loop;

            m_currentBlendTime = 0;

            float actualTimeToEnd = 0;

            if (m_player.IsInitialized)
            {
                actualTimeToEnd = m_player.Duration - m_player.Position;

                //from idle to anything
                if (actualTimeToEnd > 0 && m_player.Looping)
                    actualTimeToEnd = blendTime;
            }

            //blend always that time it was required
            m_totalBlendTime = blendTime;

            if (mode == MyPlayAnimationMode.WaitForPreviousEnd)
            {
                m_currentBlendTime = m_totalBlendTime - actualTimeToEnd;
            }
        }
        public void Play(MyAnimationDefinition animationDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale)
        {
            string model = firstPerson && !string.IsNullOrEmpty(animationDefinition.AnimationModelFPS) ? animationDefinition.AnimationModelFPS : animationDefinition.AnimationModel;
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(model));


            if (string.IsNullOrEmpty(animationDefinition.AnimationModel))
                return;


            if (animationDefinition.Status == MyAnimationDefinition.AnimationStatus.Unchecked)
            {
                var fsPath = System.IO.Path.IsPathRooted(model) ? model : System.IO.Path.Combine(MyFileSystem.ContentPath, model);
                if (!MyFileSystem.FileExists(fsPath))
                {
                    animationDefinition.Status = MyAnimationDefinition.AnimationStatus.Failed;
                    return;
                }
            }

            animationDefinition.Status = MyAnimationDefinition.AnimationStatus.OK;

            MyModel animation = MyModels.GetModelOnlyAnimationData(model);

            System.Diagnostics.Debug.Assert(animation.Animations.Clips.Count > 0);
            if (animation.Animations.Clips.Count == 0)
                return;

            System.Diagnostics.Debug.Assert(animationDefinition.ClipIndex < animation.Animations.Clips.Count);
            if (animation.Animations.Clips.Count <= animationDefinition.ClipIndex)
                return;

            AnimationClip clip = animation.Animations.Clips[animationDefinition.ClipIndex];

            if (ActualPlayer.IsInitialized)
            {
                BlendPlayer.Initialize(ActualPlayer);
            }

            // Create a clip player and assign it to this model                        
            ActualPlayer.Initialize(clip, m_skinnedEntity, 1, timeScale, frameOption, m_bones);

            m_state = AnimationBlendState.BlendIn;
            m_currentBlendTime = 0;
            m_totalBlendTime = blendTime;
        }
        bool TryGetAnimationDefinition(string animationSubtypeName, out MyAnimationDefinition animDefinition)
        {
            if (animationSubtypeName == null)
            {
                animDefinition = null;
                return false;
            }

            animDefinition = MyDefinitionManager.Static.TryGetAnimationDefinition(animationSubtypeName);
            if (animDefinition == null)
            {
                //Try backward compatibility
                //Backward compatibility
                string oldPath = System.IO.Path.Combine(MyFileSystem.ContentPath, animationSubtypeName);
                if (MyFileSystem.FileExists(oldPath))
                {
                    animDefinition = new MyAnimationDefinition()
                    { 
                        AnimationModel = oldPath,
                        ClipIndex = 0,
                    };
                    return true;
                }

                animDefinition = null;
                return false;
            }

            return true;
        }
        public void Play(MyAnimationDefinition animationDefinition, bool loop, float blendTime, float timeScale, bool justFirstFrame)
        {
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(animationDefinition.AnimationModel));

            if (string.IsNullOrEmpty(animationDefinition.AnimationModel))
                return;

            MyModel animation = MyModels.GetModelOnlyAnimationData(animationDefinition.AnimationModel);

            System.Diagnostics.Debug.Assert(animation.Animations.Clips.Count > 0);
            if (animation.Animations.Clips.Count == 0)
                return;

            System.Diagnostics.Debug.Assert(animationDefinition.ClipIndex < animation.Animations.Clips.Count);
            if (animation.Animations.Clips.Count <= animationDefinition.ClipIndex)
                return;

            AnimationClip clip = animation.Animations.Clips[animationDefinition.ClipIndex];

            if (ActualPlayer.IsInitialized)
            {
                BlendPlayer.Initialize(ActualPlayer);
            }

            // Create a clip player and assign it to this model
            ActualPlayer.Initialize(clip, m_character, 1, timeScale, justFirstFrame, m_bones);
            ActualPlayer.Looping = loop;

            m_state = AnimationBlendState.BlendIn;
            m_currentBlendTime = 0;
            m_totalBlendTime = blendTime;
        }
        protected override void OnAnimationPlay(MyAnimationDefinition animDefinition,MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion)
        {
            var currentMovementState = GetCurrentMovementState();
            if (currentMovementState != MyCharacterMovementEnum.Standing &&
                    currentMovementState != MyCharacterMovementEnum.RotatingLeft &&
                    currentMovementState != MyCharacterMovementEnum.RotatingRight &&                    
                     command.ExcludeLegsWhenMoving)
                            {
                                //In this case, we must stop all upper animations correctly
                                bonesArea = TopBody;
                                frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption;
                            }

            useFirstPersonVersion = IsInFirstPersonView;

            if (animDefinition.AllowWithWeapon)
            {
                if (!UseAnimationForWeapon)
                {
                    StoreWeaponRelativeMatrix();
                    UseAnimationForWeapon = true;
                    m_resetWeaponAnimationState = true;
                }
            }

            if (!animDefinition.LeftHandItem.TypeId.IsNull)
            {
                if (m_leftHandItem != null)
                {
                    (m_leftHandItem as IMyHandheldGunObject<Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased();
                    m_leftHandItem.Close();
                }

                m_leftHandItem = MyEntityFactory.CreateEntity(animDefinition.LeftHandItem.TypeId);
                var ob = MyEntityFactory.CreateObjectBuilder(m_leftHandItem);
                m_leftHandItem.Init(ob);

                (m_leftHandItem as IMyHandheldGunObject<Sandbox.Game.Weapons.MyDeviceBase>).OnControlAcquired(this);
                UpdateLeftHandItemPosition();

                MyEntities.Add(m_leftHandItem);
            }
        }
Esempio n. 6
0
 protected virtual void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion)
 {
 }
Esempio n. 7
0
  internal void PlayerPlay(string playerName, MyAnimationDefinition animDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale)
  {
      MyAnimationPlayerBlendPair player;
      if (TryGetAnimationPlayer(playerName, out player))
      {
          player.Play(animDefinition, firstPerson, frameOption, blendTime, timeScale);
      }
 //     else
   //       Debug.Fail("Non existing animation set");
  }
Esempio n. 8
0
        internal void PlayersPlay(string bonesArea, MyAnimationDefinition animDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale)
        {
            string[] players = bonesArea.Split(' ');

            if (animDefinition.AnimationSets != null)
            {
                foreach (var animationSet in animDefinition.AnimationSets)
                {
                    var animationSetData = new MyAnimationSetData()
                        {
                            BlendTime = blendTime,
                            Area = bonesArea,
                            AnimationSet = animationSet
                        };

                    if (animationSet.Continuous)
                    {
                        m_continuingAnimSets.Add(animationSetData);
                        continue;
                    }

                    PlayAnimationSet(animationSetData);
                }

                return;
            }

            foreach (var player in players)
            {
                PlayerPlay(player, animDefinition, firstPerson, frameOption, blendTime, timeScale);
            }
        }