Beispiel #1
0
        public static void Update(this DAnimatorComponent self)
        {
            if (self.isStop)
            {
                return;
            }

            if (self.MotionType == DMotionType.None)
            {
                return;
            }

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

                self.Animator.SetTrigger(self.MotionType.ToString());

                self.MontionSpeed = 1;
                self.MotionType   = DMotionType.None;
            }
            catch (Exception ex)
            {
                throw new Exception($"动作播放失败: {self.MotionType}", ex);
            }
        }
Beispiel #2
0
        public static void Awake(this DAnimatorComponent self)
        {
            Animator animator = self.Parent.GetComponent <DGameObjectComponent>().GameObject.GetComponent <Animator>();

            if (animator == null)
            {
                return;
            }

            if (animator.runtimeAnimatorController == null)
            {
                return;
            }

            if (animator.runtimeAnimatorController.animationClips == null)
            {
                return;
            }
            self.Animator = animator;
            foreach (AnimationClip animationClip in animator.runtimeAnimatorController.animationClips)
            {
                self.animationClips[animationClip.name] = animationClip;
            }
            foreach (AnimatorControllerParameter animatorControllerParameter in animator.parameters)
            {
                self.Parameter.Add(animatorControllerParameter.name);
            }
        }
Beispiel #3
0
        public static void SetTrigger(this DAnimatorComponent self, string name)
        {
            if (!self.HasParameter(name))
            {
                return;
            }

            self.Animator.SetTrigger(name);
        }
Beispiel #4
0
        public static void SetFloatValue(this DAnimatorComponent self, string name, float state)
        {
            if (!self.HasParameter(name))
            {
                return;
            }

            self.Animator.SetFloat(name, state);
        }
Beispiel #5
0
        public static void SetIntValue(this DAnimatorComponent self, string name, int value)
        {
            if (!self.HasParameter(name))
            {
                return;
            }

            self.Animator.SetInteger(name, value);
        }
Beispiel #6
0
        public static void SetBoolValue(this DAnimatorComponent self, string name, bool state)
        {
            if (!self.HasParameter(name))
            {
                return;
            }

            self.Animator.SetBool(name, state);
        }
Beispiel #7
0
 public static void Play(this DAnimatorComponent self, DMotionType motionType, float motionSpeed = 1f)
 {
     if (!self.HasParameter(motionType.ToString()))
     {
         return;
     }
     self.MotionType   = motionType;
     self.MontionSpeed = motionSpeed;
 }
Beispiel #8
0
        public static float AnimationTime(this DAnimatorComponent self, DMotionType motionType)
        {
            AnimationClip animationClip;

            if (!self.animationClips.TryGetValue(motionType.ToString(), out animationClip))
            {
                throw new Exception($"找不到该动作: {motionType}");
            }
            return(animationClip.length);
        }
Beispiel #9
0
        public static void RunAnimator(this DAnimatorComponent self)
        {
            if (!self.isStop)
            {
                return;
            }

            self.isStop = false;

            if (self.Animator == null)
            {
                return;
            }
            self.Animator.speed = self.stopSpeed;
        }
Beispiel #10
0
        public static void PauseAnimator(this DAnimatorComponent self)
        {
            if (self.isStop)
            {
                return;
            }
            self.isStop = true;

            if (self.Animator == null)
            {
                return;
            }
            self.stopSpeed      = self.Animator.speed;
            self.Animator.speed = 0;
        }
Beispiel #11
0
        public static void PlayInTime(this DAnimatorComponent self, DMotionType motionType, float time)
        {
            AnimationClip animationClip;

            if (!self.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;
            }
            self.MotionType   = motionType;
            self.MontionSpeed = motionSpeed;
        }
Beispiel #12
0
 public static bool HasParameter(this DAnimatorComponent self, string parameter)
 {
     return(self.Parameter.Contains(parameter));
 }
Beispiel #13
0
 public static void ResetAnimatorSpeed(this DAnimatorComponent self)
 {
     self.Animator.speed = self.stopSpeed;
 }
Beispiel #14
0
 public static void SetAnimatorSpeed(this DAnimatorComponent self, float speed)
 {
     self.stopSpeed      = self.Animator.speed;
     self.Animator.speed = speed;
 }