public void AddPlayerScoreElement()
    {
        Texture2D lastFace = ScreenshotManager.FaceScreenshots[ScreenshotManager.FaceScreenshots.Count - 1];

        byte[]             lastFaceJpg = ImageConversion.EncodeToJPG(lastFace, 60);
        PlayerScoreElement element     = new PlayerScoreElement(PlayerScore.Value, lastFaceJpg);

        PlayerScoreElements.Add(element);

        SaveData();
    }
Пример #2
0
    void Start()
    {
        // Linking scripts.
        globalData         = FindObjectOfType <GlobalData>().GetComponent <GlobalData>();
        gameDefaults       = globalData.GameDefaults;
        audioManager       = FindObjectOfType <AudioManager>().GetComponent <AudioManager>();
        gamePreprocessor   = FindObjectOfType <GamePreprocessor>().GetComponent <GamePreprocessor>();
        playerScoreElement = FindObjectOfType <PlayerScoreElement>().GetComponent <PlayerScoreElement>();
        menuManager        = FindObjectOfType <MenuManager>().GetComponent <MenuManager>();


        // Initializes GameSetupData object.
        gamePreprocessor.NewQuestionsAndAnswers();
        gameTimeLimit = gamePreprocessor.GameSetupData.GameTimeLimit;


        // Finding gameobjects in game.
        answerButtons             = GameObject.FindGameObjectsWithTag("AnswerButton");
        answerFeedbackCanvasGroup = GameObject.Find("Image_AnswerFeedback").GetComponent <CanvasGroup>();
        answerText            = GameObject.Find("Answer_Text").GetComponent <Text>();
        answerTextCanvasGroup = GameObject.Find("Answer_Text").GetComponent <CanvasGroup>();
        clearAnswerButton     = GameObject.Find("Btn_ClearAnswer");
        questionText          = GameObject.Find("Area_Question_Text").GetComponent <Text>();

        gameFinishScreen         = GameObject.Find("GameFinishScreen");
        gameFinishScreenContent  = GameObject.Find("GameFinishScreenContent");
        gameFinishScreenSubTitle = GameObject.Find("GameFinishScreenSubTitle").GetComponent <Text>();
        gameFinishScreenTitle    = GameObject.Find("GameFinishScreenTitle").GetComponent <Text>();

        timerSliderFillLeft  = GameObject.Find("TimerSliderFillLeft").GetComponent <Image>();
        timerSliderFillRight = GameObject.Find("TimerSliderFillRight").GetComponent <Image>();
        timerSliderLeft      = GameObject.Find("TimerSliderLeft").GetComponent <Slider>();
        timerSliderRight     = GameObject.Find("TimerSliderRight").GetComponent <Slider>();
        timerText            = GameObject.Find("Text_TimeRemaining").GetComponent <Text>();

        // Adds listeners for answer button sounds.
        foreach (GameObject go in GameObject.FindGameObjectsWithTag("AnswerButton"))
        {
            go.GetComponentInChildren <Button>().onClick.AddListener(() => audioManager.Play("Btn_Click"));
        }


        // Disables gameFinishScreen.
        gameFinishScreen.GetComponent <CanvasGroup>().alpha        = 0f;
        gameFinishScreenContent.GetComponent <CanvasGroup>().alpha = 0f;


        // Time-limit.
        timerIsOn = true;
        incrementalSliderValue = gameTimeLimit / 4;

        timerSliderFillLeft.color  = gameDefaults.DefaultColors[Enum_Colors.GREEN];
        timerSliderFillRight.color = gameDefaults.DefaultColors[Enum_Colors.GREEN];

        timerSliderLeft.maxValue  = gameTimeLimit;
        timerSliderRight.maxValue = gameTimeLimit;

        timerSliderLeft.value  = gameTimeLimit;
        timerSliderRight.value = gameTimeLimit;


        // Initial labels update.
        UpdateQuestionText();
    }
Пример #3
0
    public override Tween Arrive(bool animate = true)
    {
        Tween t = base.Arrive(animate);

        // Clear any previous items (although there shouldn't be any).
        int childCount = PlayerScoresLayout.transform.childCount;

        for (int i = childCount - 1; i >= 0; i--)
        {
            Destroy(PlayerScoresLayout.transform.GetChild(i).gameObject);
        }

        Sequence seq = DOTween.Sequence();

        var orderedPlayers = GameManager.Instance.PlayerInfos.OrderByDescending(x => x.Points).ToList();
        //float highestScore = GameManager.Instance.PlayerInfos.Max((x,y) => x.Points > y.Po);
        var playerInfos = GameManager.Instance.PlayerInfos;

        for (int i = 0; i < playerInfos.Count; i++)
        {
            PlayerScoreElement clone = Instantiate(PlayerScoreElementPrefab);
            clone.Avatar.sprite   = playerInfos[i].Avatar.Sprite;
            clone.PointsText.text = "0";
            clone.FillFG.color    = playerInfos[i].Avatar.Color;

            // Avatars pop in at the very start.
            clone.Avatar.transform.localScale = Vector3.zero;
            seq.Insert(0, clone.Avatar.transform.DOScale(Vector3.one, AvatarPopDuration).SetEase(AvatarPopEase));
            seq.InsertCallback(0, () => SFX.Play("sticker_appear"));

            float maxHeight   = clone.FillBG.rectTransform.rect.height;
            float initialFill = Mathf.Lerp(0, maxHeight, playerInfos[i].Points / orderedPlayers[0].AggregatePoints);
            float finalFill   = Mathf.Lerp(0, maxHeight, playerInfos[i].AggregatePoints / orderedPlayers[0].AggregatePoints);

            Vector2 initialFillSizeDelta = new Vector2(clone.FillFG.rectTransform.sizeDelta.x, initialFill);
            Vector2 finalFillSizeDelta   = new Vector2(clone.FillFG.rectTransform.sizeDelta.x, finalFill);
            Vector2 initialPos           = new Vector2(0, initialFillSizeDelta.y);
            Vector2 finalPos             = new Vector2(0, finalFillSizeDelta.y);

            // Find position of the player.
            int position = orderedPlayers.FindIndex(x => x == playerInfos[i]);
            // Find reverse position of the player for use in calculations (0 is worst -- descending order).
            int index = (orderedPlayers.Count - 1) - position;
            // We want to raise first and second place at the same time, so use the same calculation in that situation.
            int initialMultiplier = position == 0 || position == 1 ? orderedPlayers.Count - 2 : index;
            int finalMultiplier   = orderedPlayers.Count - 1;

            seq.Insert(AvatarPopDuration + InitialRiseDuration * initialMultiplier,
                       clone.FillFG.rectTransform.DOSizeDelta(initialFillSizeDelta, InitialRiseDuration).SetEase(RiseEase));
            seq.Insert(AvatarPopDuration + InitialRiseDuration * initialMultiplier,
                       clone.Avatar.rectTransform.DOAnchorPos(initialPos, InitialRiseDuration).SetEase(RiseEase));
            seq.Insert(AvatarPopDuration + InitialRiseDuration * initialMultiplier,
                       DOTween.To(() => 0, x => clone.PointsText.text = x.ToString("N0"), playerInfos[i].Points, InitialRiseDuration));
            seq.InsertCallback(AvatarPopDuration + InitialRiseDuration * initialMultiplier, () => SFX.Play("score_start"));

            // These need to be callbacks because they must be formulated at runtime (they add to the existing position / sizedelta).
            //  If they aren't callbacks, then they do nothing because they're made at compile time, which has different values.
            seq.InsertCallback(AvatarPopDuration + InitialRiseDuration * finalMultiplier + index * GoldBonusInbetweenDuration + GoldBonusDuration,
                               () => clone.FillFG.rectTransform.DOSizeDelta(finalFillSizeDelta, FinalRiseDuration).SetEase(RiseEase));
            seq.InsertCallback(AvatarPopDuration + InitialRiseDuration * finalMultiplier + index * GoldBonusInbetweenDuration + GoldBonusDuration,
                               () => {
                clone.Avatar.rectTransform.DOAnchorPos(finalPos, FinalRiseDuration).SetEase(RiseEase);
                SFX.Play("coins");
            });
            // Clone i because it may change between now and when the closure is run.
            var iclone = i;
            seq.InsertCallback(AvatarPopDuration + InitialRiseDuration * finalMultiplier + index * GoldBonusInbetweenDuration + GoldBonusDuration,
                               () => DOTween.To(() => playerInfos[iclone].Points, x => clone.PointsText.text = x.ToString("N0"), playerInfos[iclone].AggregatePoints, FinalRiseDuration));

            //SFX.Play("score_start");
            clone.transform.SetParent(PlayerScoresLayout.transform, false);
        }

        GoldBonusText.transform.localScale = Vector3.zero;
        seq.Insert(AvatarPopDuration + InitialRiseDuration * (playerInfos.Count - 1),
                   GoldBonusText.transform.DOScale(Vector3.one, GoldBonusDuration).SetEase(GoldBonusEase));

        // For now, just do this.
        seq.OnComplete(() => Invoke("LoadNextScene", 3f));

        if (t != null)
        {
            seq.Pause();
            t.onComplete += () => seq.Play();
        }
        else if (Initiate.IsLoading)
        {
            seq.Pause();
            Initiate.onFinishFading += () => seq.Play();
        }

        return(t);
    }