FlowManager.TriggerNextAction C# (CSharp) Method

TriggerNextAction() private method

private TriggerNextAction ( ) : void
return void
    private void TriggerNextAction()
    {
        if (!IsBusy && m_QueuedActions.Count > 0)
        {
            // Get the first in action in queue.
            m_CurrentActionData = m_QueuedActions[0];
            FlowViewData viewData = m_ActionController.GetViewData(m_CurrentActionData.ViewId);

            m_QueuedActions.Remove(m_CurrentActionData);

            View topView = GetTopView();
            if (topView != null && viewData != null && viewData.ViewId == topView.ViewData.ViewId)
            {
                topView.HandleAction(m_CurrentActionData);

                TriggerNextAction();
            }
            else if (string.IsNullOrEmpty(m_CurrentActionData.ViewId) || viewData != null)
            {
                // Find if the view is already opened.
                for (int i = m_OpenedViews.Count - 1; i >= 0; --i)
                {
                    View view = m_OpenedViews[i];

                    // If already in the queue, it gains the focus.
                    if ((string.IsNullOrEmpty(m_CurrentActionData.ViewId) && view.ViewData == GetBeforeTopView()) ||
                        (viewData != null && view.ViewData.ViewId == viewData.ViewId))
                    {
                        m_GainingFocusView = view;

                        // If a popup, or we are closing the top view.
                        if (string.IsNullOrEmpty(m_CurrentActionData.ViewId) || m_CurrentActionData.IsPopup)
                        {
                            // Close all popup on higher levels than one opening.
                            for (int j = i + 1; j < m_OpenedViews.Count; ++j)
                            {
                                if (m_LosingFocusView == m_OpenedViews[j])
                                {
                                    m_LosingFocusView = null;
                                }
                                m_ClosingViews.Add(m_OpenedViews[j]);
                            }
                        }
                    }
                    // If not in the queue, close/hide the other ones.
                    // We don't want to close view in the case we're just closing the top one.
                    else if (!string.IsNullOrEmpty(m_CurrentActionData.ViewId))
                    {
                        // If we are opening a popup, hide them.
                        if (m_CurrentActionData.IsPopup)
                        {
                            // If it's the top view.
                            if (topView != null && view.ViewData == topView.ViewData)
                            {
                                // Losing focus because we are opening a new view.
                                m_LosingFocusView = view;
                            }
                        }
                        // If we are not opening a popup, close everything.
                        else
                        {
                            m_ClosingViews.Add(view);
                        }
                    }
                }

                // If nothing is gaining focus, we open a new view.
                if (viewData != null && m_GainingFocusView == null)
                {
                    m_OpeningView = viewData;
                }

                // Display the loading screen if requested.
                if (m_OpeningView != null && m_CurrentActionData.UseLoadingScreen)
                {
                    m_LoadingScreen.transform.position = new Vector3(0.0f, 0.0f, (m_OpenedViews.Count + 1) * -m_ActionController.ViewDepth);
                    m_LoadingScreen.SetActive(true);
                }

                TriggerNextView();
            }
            else
            {
                Debug.LogError("FlowManager, TriggerNextAction: Cannot trigger '" + m_CurrentActionData.ActionName + "' in current scene (" + (viewData == null ? "NONE" : viewData.ViewId) + ").");
                TriggerNextAction();
            }
        }
    }