Пример #1
0
        public void Update()
        {
            if (this.isStop)
            {
                return;
            }

            if (this.MotionType == AnimatorMotionType.None)
            {
                return;
            }

            try
            {
                this.Animator.SetFloat("MotionSpeed", this.MontionSpeed);

                //设置触发器
                this.Animator.SetTrigger(this.MotionType.ToString());

                this.MontionSpeed = 1;

                this.MotionType = AnimatorMotionType.None;
            }
            catch (Exception ex)
            {
                throw new Exception($"动作播放失败:{this.MotionType}", ex);
            }
        }
Пример #2
0
        public void Set(AnimatorMotionType motionType, float motionSpeed = 1f)
        {
            if (!this.HasParameter(MotionType.ToString()))
            {
                return;
            }

            this.MotionType = motionType;

            this.MontionSpeed = motionSpeed;
        }
Пример #3
0
        /// <summary>
        /// 获取动画时间
        /// </summary>
        /// <param name="motionType"></param>
        /// <returns></returns>
        public float GetAnimationTime(AnimatorMotionType motionType)
        {
            AnimationClip animationClip;

            if (this.animationClips.TryGetValue(motionType.ToString(), out animationClip))
            {
                throw new Exception($"找不到该动作:{motionType}");
            }

            return(animationClip.length);
        }
Пример #4
0
        public void SetInTime(AnimatorMotionType motionType, float time = 1)
        {
            AnimationClip animationClip;

            if (this.animationClips.TryGetValue(motionType.ToString(), out animationClip))
            {
                throw new Exception($"找不到该动作:{motionType}");
            }

            float motionSpeed = animationClip.length / time;

            //检测是否合理

            if (motionSpeed < 0.01f || motionSpeed > 1000f)
            {
                Log.Error($"motionSpeed数值异常,{motionSpeed},此动作跳过");

                return;
            }

            this.MotionType = motionType;

            this.MontionSpeed = motionSpeed;
        }