Example #1
0
    public void Init(string initialQuestion, string[] initialAnswers = null)
    {
        toggleGroup  = layoutPanelTransform.GetComponent <ToggleGroup2>();
        answerInputs = new List <InputField>();

        var answers = new string[0];

        if (initialAnswers == null || initialAnswers.Length <= 1)
        {
            answerCorrect = 0;
        }
        else
        {
            answerCorrect = Convert.ToInt32(initialAnswers[0]);
            answers       = new string[initialAnswers.Length - 1];
            Array.Copy(initialAnswers, 1, answers, 0, answers.Length);
        }

        question.text = initialQuestion;

        foreach (var answer in answers)
        {
            AddAnswer(answer, answerCount == answerCorrect);
        }

        question.onValueChanged.AddListener(_ => OnInputChangeColor(question));
        addAnswerButton.onClick.AddListener(() => OnButtonChangeColor(addAnswerButton));

        defaultColor = question.image.color;
    }
    public void Init(string initialTitle, List <string> initialAnswers, int initialCorrect = -1)
    {
        entries       = new List <MultipleChoiceImageEntry>();
        question.text = initialTitle;
        toggleGroup   = gameObject.AddComponent <ToggleGroup2>();
        answerCorrect = initialCorrect;

        if (initialAnswers != null)
        {
            for (int i = 0; i < initialAnswers.Count; i++)
            {
                CreateNewEntry(initialAnswers[i], i == initialCorrect);
            }
        }

        question.onValueChanged.AddListener(_ => OnInputChangeColor(question));

        toggleGroup.onToggleGroupChanged.AddListener(OnSelectCorrectImage);
    }
    public void Init(string newTitle, Guid newGuid, List <Area> newAreas, int newCorrect)
    {
        defaultColor      = title.image.color;
        defaultPanelColor = areaList.parent.parent.GetComponent <Image>().color;

        guid       = newGuid;
        title.text = newTitle;
        title.onValueChanged.AddListener(_ => OnInputChange(title));
        answerCorrect = newCorrect;
        toggleGroup   = gameObject.AddComponent <ToggleGroup2>();

        if (newAreas != null)
        {
            answerAreas = newAreas;
            for (int i = 0; i < answerAreas.Count; i++)
            {
                var filename = answerAreas[i].miniatureName;
                var path     = Path.Combine(Application.persistentDataPath, newGuid.ToString(), SaveFile.miniaturesPath);
                var fullPath = Path.Combine(path, filename);

                var go    = Instantiate(multipleChoiceAreaEntryPrefab, areaList);
                var entry = go.GetComponent <MultipleChoiceAreaEntry>();
                StartCoroutine(entry.SetArea(answerAreas[i], fullPath));

                entry.deleteButton.onClick.RemoveAllListeners();
                entry.deleteButton.onClick.AddListener(() => OnDeleteArea(go));
                entry.editButton.onClick.RemoveAllListeners();
                entry.editButton.onClick.AddListener(() => OnEditArea(go));
                toggleGroup.RegisterToggle(entry.toggle);
                entry.toggle.group = toggleGroup;

                entry.toggle.SetIsOnWithoutNotify(i == answerCorrect);
                defaultToggleColor = entry.toggle.image.color;
            }
        }
        else
        {
            answerAreas = new List <Area>();
        }

        toggleGroup.onToggleGroupChanged.AddListener(OnSelectCorrectArea);
    }