Пример #1
0
        /// <summary>
        /// 切换动画
        /// </summary>
        /// <param name="id">动画ID</param>
        /// <param name="animDeltaTime">补偿上下帧间的误差</param>
        /// <returns></returns>

        bool ChangeAction(string id, int animDeltaTime)
        {
            int indexAction = ActionHelp.GetActionIndex(_actionGroupData, id);

            if (indexAction < 0)
            {
                return(false);
            }

            ChangeAction(indexAction, animDeltaTime);

            //if (beforName == _activeActionData.Name)
            //{
            //    //if (oldAction.Name != "Idle")
            //    //    Debug.Log("asdf");
            //    beforName = _activeActionData.Name;
            //}
            //else
            //{
            //    if (beforName != "Idle")
            //        Debug.Log("asdf");
            //}

            return(true);
        }
Пример #2
0
        /// <summary>
        /// 处理中断
        /// 立即模式 立即由切换Action.
        /// 等待完成 等待动画播放完成后执行.
        /// </summary>
        /// <param name="interrupt"></param>
        /// <returns></returns>

        bool LinkAction(ActionInterrupt interrupt)
        {
            if (ActionHelp.GetActionIndex(_actionGroupData, interrupt.ActionID) == -1)
            {
                Debug.LogError(string.Format("Can't find ActionID {0}", interrupt.ActionID.ToString()));
                return(false);
            }

            bool connectImmediately = interrupt.ConnectMode == ActionInterruptConnectMode.Immediately;

            if (interrupt.ConnectMode == ActionInterruptConnectMode.WaitFinish)
            {
                //  中断触发的时机是当前动画播放完成
                int actualQueuedTime = interrupt.ConnectTime <= 100 ?
                                       _activeActionData.AnimTime * interrupt.ConnectTime / 100 : // [0-100] AnimTime
                                       _activeActionData.AnimTime + _activeActionData.PoseTime * (interrupt.ConnectTime - 100) / 100;

                if (actualQueuedTime <= _actionTime)
                {
                    connectImmediately = true;
                }

                _queuedInterrupt     = interrupt;
                _queuedInterruptTime = actualQueuedTime;
            }

            //  立即中断到指定动画
            if (connectImmediately || interrupt.ConnectMode == ActionInterruptConnectMode.Immediately)
            {
                ChangeAction(interrupt.ActionID, 0);
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// 获取下一个动画Key
        /// 0 - 100 <= AnimTime
        /// 101-199 <= TotalTime (这个是算上pose时间)
        /// 200 pose时间也结束了
        /// </summary>
        /// <param name="deltaTime"></param>
        /// <returns></returns>
        int GetNextKey(int deltaTime)
        {
            if (_activeActionData == null)
            {
                return(-1);
            }

            int currentTime = _actionTime + deltaTime;

            // [0-100]
            if (currentTime <= _activeActionData.AnimTime)
            {
                return(currentTime * 100 / _activeActionData.AnimTime);
            }

            // [200-...]
            if (currentTime >= ActionHelp.GetActionTotalTime(_activeActionData))
            {
                return(200);
            }

            // [101 - TotalTime(animTime + poseTime)]
            //int leftTime = currentTime - _activeActionData.AnimTime;
            return(100 + (currentTime - _activeActionData.AnimTime) * 100 / _activeActionData.PoseTime);
        }
Пример #4
0
        void TickAction(int deltaTime, float dt)
        {
            //if (ProcessInterruptEveryFrame())
            //{
            //    return;
            //}

            // 检测是否有[等待]中断动画
            if (ProcessQueuedInterrupt(deltaTime))
            {
                return;
            }


            int  nextActionTime       = 0;
            bool thisActionIsFinished = false;

            if ((_actionTime + deltaTime) > ActionHelp.GetActionTotalTime(_activeActionData))
            {
                nextActionTime = deltaTime;

                deltaTime       = ActionHelp.GetActionTotalTime(_activeActionData) - _actionTime;
                nextActionTime -= deltaTime;

                thisActionIsFinished = true;
            }



            int nextActionKey = GetNextKey(deltaTime);

            tempNextKey = nextActionKey;
            if (nextActionKey > _actionKey)
            {
                int nextKeyTime;
                if (nextActionKey > 100)
                {
                    nextKeyTime = (_activeActionData.AnimTime + _activeActionData.PoseTime) * nextActionKey / 200;
                }
                else
                {
                    nextKeyTime = _activeActionData.AnimTime * nextActionKey / 100;
                }

                //  事件处理
                ProcessEvent(nextKeyTime, deltaTime);

                //  hit define

                //  中断处理
                if (ProcessActionInterruptList(_actionKey, nextActionKey))
                {
                    return;
                }


                //  如果有Pose,尝试进入Pose状态
                if (_activeActionData.PoseTime > 0 && _actionKey < 100 && nextActionKey >= 100)
                {
                    //  enter posetime
                    //  animation speed 0.001f
                    _ownerUnit.OnEnterPoseTime();
                }

                //  hack the event interrupts.
            }


            ProcessMoving(dt);

            _actionTime += deltaTime;
            beforKey     = _actionKey;
            _actionKey   = nextActionKey;

            if (thisActionIsFinished)
            {
                ProcessAnimFinish(nextActionTime);
            }
        }