コード例 #1
0
    IEnumerator RunPollCountdown()
    {
        ContentManager   content          = ContentManager.Instance;
        PanelManager     panelManager     = PanelManager.Instance;
        CenterScreen     centerScreen     = CenterScreen.Instance;
        SideMenu         sideMenu         = SideMenu.Instance;
        CenterMenu       centerMenu       = CenterMenu.Instance;
        RightMenu        rightMenu        = RightMenu.Instance;
        LeftMenu         leftMenu         = LeftMenu.Instance;
        LargeCubeCluster largeCubeCluster = LargeCubeCluster.Instance;
        SmallCubeCluster smallCubeCluster = SmallCubeCluster.Instance;
        EqualCubeCluster equalCubeCluster = EqualCubeCluster.Instance;

        float pollCountdown = StartupSettings.Instance.PollCountdown;

        PlayerManager playerManager = PlayerManager.Instance;
        var           activePlayers = playerManager.ActivePlayers;

        yield return(new WaitForSeconds(m_beforeCountdownTime));

        //Wait for show icon above to go away...
        yield return(new WaitForSeconds(1f));

        Player.ShowMoveCubeText   = false;
        Player.CountdownValue     = (int)pollCountdown;
        Player.ShowCountdownValue = true;

        StartCoroutine(Player.RunCountdown(null));
        yield return(new WaitForSeconds(pollCountdown + 1f));

        Player.ShowCountdownValue = false;
        yield return(new WaitForSeconds(1f));

        m_yesNoActive = false;
        rightMenu.ShowActiveNo(false);
        centerMenu.ShowActiveYes(false);
        rightMenu.HideInactiveNo(false);
        centerMenu.HideInactiveYes(false);

        {   //Poll results start here...
            bool leftHasNotChanged  = true;
            bool rightHasNotChanged = true;

            foreach (Player player in playerManager.ActivePlayers)
            {
                if (panelManager.ContainsPlayer(player, 1))      //center panel...
                {
                    leftHasNotChanged     = false;
                    m_answerInfo.answerA += 1;
                }
                else if (panelManager.ContainsPlayer(player, 2))     //right panel...
                {
                    rightHasNotChanged    = false;
                    m_answerInfo.answerB += 1;
                }
            }

            bool largeIsRight = m_answerInfo.answerA < m_answerInfo.answerB;
            bool smallIsRight = m_answerInfo.answerA > m_answerInfo.answerB;

            //Filters players from cube clusters they didn't vote for...
            FilterActivePlayers(largeIsRight, smallIsRight);

            centerScreen.MoveUpHeader(true);
            centerMenu.MoveDownYes(true);
            rightMenu.MoveDownNo(true);

            yield return(new WaitForSeconds(1f));

            CubeCluster.HidePlayerCubes = false;
            Player.ShowColor            = false;

            float total        = m_answerInfo.answerA + m_answerInfo.answerB;
            int   leftPercent  = (int)((m_answerInfo.answerA / total) * 100);
            int   rightPercent = (int)((m_answerInfo.answerB / total) * 100);

            centerMenu.StartPollAPercentCountdown(m_percentCountdownTime, leftPercent);
            rightMenu.StartPollAPercentCountdown(m_percentCountdownTime, rightPercent);

            largeCubeCluster.InstantShowCluster();
            smallCubeCluster.InstantShowCluster();
            equalCubeCluster.InstantShowCluster();

            if (largeIsRight)
            {
                centerMenu.ShowSmallResults(true);
                rightMenu.ShowLargeResults(true);
            }
            else if (smallIsRight)
            {
                centerMenu.ShowLargeResults(true);
                rightMenu.ShowSmallResults(true);
            }
            else    //They are equal...
            {
                rightMenu.ShowLargeResults(true);
                centerMenu.ShowEqualResults(true);
            }

            yield return(new WaitForSeconds(m_percentCountdownTime));

            yield return(new WaitForSeconds(2f));

            if (leftHasNotChanged)
            {
                centerMenu.HideLargePercent(true);
                centerMenu.HideSmallPercent(true);

                if (largeIsRight)
                {
                    smallCubeCluster.Explode();
                }
                else if (smallIsRight)
                {
                    largeCubeCluster.Explode();
                }
                else
                {
                    equalCubeCluster.Explode();
                }
            }
            if (rightHasNotChanged)
            {
                rightMenu.HideLargePercent(true);
                rightMenu.HideSmallPercent(true);

                if (largeIsRight)
                {
                    largeCubeCluster.Explode();
                }
                else if (smallIsRight)
                {
                    smallCubeCluster.Explode();
                }
                else
                {
                    largeCubeCluster.Explode();
                }
            }

            yield return(new WaitForSeconds(StartupSettings.Instance.AfterPollATimeout));

            centerMenu.ShowLargeResults(false);
            centerMenu.ShowSmallResults(false);
            centerMenu.ShowEqualResults(false);
            rightMenu.ShowLargeResults(false);
            rightMenu.ShowSmallResults(false);
            rightMenu.ShowEqualResults(false);

            //Updating poll answers and starting takeaway...
            content.OpenConnection();
            content.PutPollAnswers(m_answerInfo);
            PollManager.Instance.StartTakeaway(m_poll.Question_Id);
            content.CloseConnection();

            yield return(new WaitForSeconds(2f));

            centerMenu.HideLargePercent(false);
            rightMenu.HideLargePercent(false);
            centerMenu.HideSmallPercent(false);
            rightMenu.HideSmallPercent(false);

            largeCubeCluster.DestroyCluster();
            largeCubeCluster.CreateCluster();
            smallCubeCluster.DestroyCluster();
            smallCubeCluster.CreateCluster();
            equalCubeCluster.DestroyCluster();
            equalCubeCluster.CreateCluster();

            //Cleanup...
            largeCubeCluster.FilteredPlayers.Clear();
            smallCubeCluster.FilteredPlayers.Clear();
            equalCubeCluster.FilteredPlayers.Clear();
        }

        //Cleanup...
        Player.ShowColor          = false;
        Player.ShowInactiveColor  = true;
        Player.ShowCountdownValue = false;
        Player.ShowMoveIcon       = true;
        StartCoroutine(Player.ShowHashtagOverTime(m_hashtagShowTime));

        sideMenu.ShowBackground(false);
        rightMenu.ShowBackground(false);
        centerMenu.ShowBackground(false);
        leftMenu.ShowBackground(false);
        centerScreen.ShowHeader(false);
        centerMenu.ShowPollA(false);
        rightMenu.ShowPollA(false);

        //Wait some time for animations above to take effect...
        yield return(new WaitForSeconds(1.5f));

        centerScreen.ResetHeader();
        centerMenu.ResetYesAnimator();
        rightMenu.ResetNoAnimator();

        yield return(new WaitForSeconds(1.5f));

        //Allow streaming cubes to start streaming in again...
        //TODO: Should be AppState.TAKE_AWAY...
        AppManager.State = AppManager.AppState.ATTRACT_CUBES;
        PanelManager.Instance.ClearAllPanels();
    }