Exemplo n.º 1
0
    private IEnumerator WaitForFeedback(Dialog dialog, Action <Dialog, ResponseStatus> callback)
    {
        var dismissTime = PhoneTime.Time + AutoDismissTime;

        while ((_expanded || PhoneTime.Time < dismissTime) && _answer < 0)
        {
            yield return(null);
        }

        if (_answer >= 0)
        {
            if (_answer == _correctAnswer)
            {
                callback?.Invoke(dialog, ResponseStatus.Correct);
            }
            else
            {
                callback?.Invoke(dialog, ResponseStatus.Incorrect);
            }
        }
        else
        {
            callback?.Invoke(dialog, ResponseStatus.Ignored);
        }

        Animator.SetBool("Display", false);

        DismissButton.gameObject.SetActive(false);
    }
Exemplo n.º 2
0
    public void ShowMessage(Dialog dialog, Action <Dialog, ResponseStatus> callback)
    {
        _answer   = -1;
        _expanded = false;

        DismissButton.gameObject.SetActive(true);

        if (!string.IsNullOrEmpty(dialog.Sender))
        {
            var contact = _contacts[dialog.Sender];
            Background.color = contact.BGColor;
            Photo.sprite     = contact.ProfileImage;
            Name.text        = dialog.Sender;
        }

        _fullText = dialog.SenderMessage;

        NotifSound.Play();


        if (dialog.SenderMessage.Length > 15)
        {
            Content.text = _fullText.Substring(0, 15) + "...";
        }
        else
        {
            Content.text = _fullText;
        }

        foreach (var answerButton in AnswerButtons)
        {
            answerButton.gameObject.SetActive(false);
        }

        foreach (var answerButton in AnswerButtons)
        {
            answerButton.gameObject.SetActive(false);
        }

        _answerCount   = dialog.WrongResponses.Count + 1;
        _correctAnswer = UnityEngine.Random.Range(0, _answerCount);

        for (int i = 0; i < _answerCount; ++i)
        {
            if (i == _correctAnswer)
            {
                AnswerButtons[i].GetComponentInChildren <TextMeshProUGUI>().text = dialog.CorrectResponse;
            }
            else if (i > _correctAnswer)
            {
                AnswerButtons[i].GetComponentInChildren <TextMeshProUGUI>().text = dialog.WrongResponses[i - 1];
            }
            else
            {
                AnswerButtons[i].GetComponentInChildren <TextMeshProUGUI>().text = dialog.WrongResponses[i];
            }
        }

        Animator.ResetTrigger("Expand");
        Animator.SetBool("Display", true);
        StartCoroutine(WaitForFeedback(dialog, callback));
    }