public void SetButtons(BookQuestion bookQuestion)
    {
        List <BookAnswer> bundledAnswers = bookQuestion.BundledAnswers;
        List <Button>     buttons        = new List <Button>();

        if (bundledAnswers.Count == 0)
        {
            return;
        }

        for (int i = 0; i < bundledAnswers.Count; i++)
        {
            buttons.Add(Instantiate(buttonQuestionTemplate, layout).GetComponent <Button>());
        }

        for (int i = 0; i < buttons.Count; i++)
        {
            int randomIndex = Random.Range(0, bundledAnswers.Count);
            buttons[i].gameObject.SetActive(true);
            buttons[i].GetComponentInChildren <TMPro.TextMeshProUGUI>().text = bundledAnswers[randomIndex].content;

            if (bundledAnswers[randomIndex] == bookQuestion.correctAnswer)
            {
                buttons[i].onClick.AddListener(OnCorrect);
            }
            else
            {
                buttons[i].onClick.AddListener(OnIncorrect);
            }
            buttons[i].onClick.AddListener(HideUI);

            bundledAnswers.RemoveAt(randomIndex);
        }
    }
    public void DisplayBookQuestion(BookQuestion bookQuestion)
    {
        if (IsActive)
        {
            return;
        }

        RemoveButtons();
        onShowUI?.Invoke();
        IsActive = !IsActive;
        questionContentText.text = bookQuestion.question;
        bookIndexText.text       = "Book " + (BookManager.Instance.BooksAnswered + 1) + " of " + "#";
        SetButtons(bookQuestion);
    }
Пример #3
0
    private void Awake()
    {
        _unansweredQuestions.AddRange(questionDatabase.bookQuestions);

        GameObject[] objs = GameObject.FindGameObjectsWithTag("BookSpawn").ToArray();
        for (int i = 0; i < objs.Length; i++)
        {
            _spawnLocations.Add(objs[i].transform);
        }

        for (int i = 0; i < _spawnLocations.Count; i++)
        {
            _spawnLocations[i].gameObject.SetActive(false);
        }

        _currentQuestion = startQuestion;
    }
Пример #4
0
    public void SpawnBook()
    {
        if (!bookPrefab || _spawnLocations.Count == 0 || _unansweredQuestions.Count == 0)
        {
            return;
        }
        if (_currentSpawnedBook && _currentSpawnedBook.GetComponent <BookWorldQuestion>().IsActive)
        {
            return;
        }

        EelAI eelAI = FindObjectOfType <EelAI>();

        if (_count == 0)
        {
            eelAI.state = SimpleAI.State.Wander;
            eelAI.GetComponent <EnemyActor>().canKill = true;
            DialogueManager.Instance.Stop();
        }

        Destroy(_currentSpawnedBook);

        int randomQuestionIndex = Random.Range(0, _unansweredQuestions.Count - 1);

        _currentQuestion = _unansweredQuestions[randomQuestionIndex];

        _currentSpawnedBook = Instantiate(bookPrefab);
        _currentSpawnedBook.GetComponent <BookWorldQuestion>().bookQuestion = _currentQuestion;

        List <Transform> locationsWithoutPrevious = new List <Transform>();

        locationsWithoutPrevious.AddRange(_spawnLocations);
        if (_currentSpawnLocation)
        {
            locationsWithoutPrevious.Remove(_currentSpawnLocation);
        }

        int randomLocationIndex = Random.Range(0, locationsWithoutPrevious.Count - 1);

        _currentSpawnLocation = locationsWithoutPrevious[randomLocationIndex];
        _currentSpawnedBook.transform.position = new Vector3(_currentSpawnLocation.position.x, bookPrefab.transform.position.y, _currentSpawnLocation.position.z);
    }