Beispiel #1
0
    public void RunAction(IGameAction action)
    {
        if (_currentAction != null)
        {
            return;
        }

        //Пропуск хода
        if (action == null)
        {
            EndAction(null);
            return;
        }

        if (action.Check())
        {
            OnActionStart?.Invoke(action);
            _currentAction = action;
            action.status  = actionStatuses.start;
            StartCoroutine(action.Execute());
        }
        else
        {
            Debug.LogFormat("Действие {0} не прошло проверку", action.GetType());
        }
    }
Beispiel #2
0
        private void Update()
        {
            distanceTraveled = distanceToTravel + Vector3.Distance(transform.position, m_endposition);

            // [TODO] Remove Action Preview
            if (m_nextAction != null)
            {
                m_previewAction = m_nextAction;
            }

            m_Timer = m_timeBeforeNextAction;
            if (m_nextAction != null)
            {
                m_timeBeforeNextAction -= Time.deltaTime;

                if (m_timeBeforeNextAction <= 0)
                {
                    m_isLeftButtonPressed  = false;
                    m_isRightButtonPressed = false;

                    m_IsPlayingAnimation = true;
                    if (m_previousAction != null)
                    {
                        if (m_nextAction.actionType == m_previousAction.actionType)
                        {
                            if (m_previousAction.actionType == RobotActionType.StepLeft)
                            {
                                m_nextAction = new RobotAction(m_AnimationTimeStagger, RobotActionType.StaggerLeft);
                            }
                            else
                            {
                                m_nextAction = new RobotAction(m_AnimationTimeStagger, RobotActionType.StaggerRight);
                            }
                        }
                    }
                    m_robotAnimation.PlayAnimation(m_nextAction);
                    m_robotMove.performAction(m_nextAction);
                    if (m_nextAction.actionType == RobotActionType.StepRight || m_nextAction.actionType == RobotActionType.StepLeft)
                    {
                        m_previousAction = m_nextAction;
                    }
                    m_previewAction = m_nextAction;
                    m_nextAction    = null;
                    if (OnActionStart != null)
                    {
                        OnActionStart.Invoke();
                    }
                }
            }

            m_robotMove.Update();
            m_robotAnimation.Update();
        }