Esempio n. 1
0
    private void CreateNewEntry(string path, bool correct)
    {
        var albumEntry = Instantiate(multipleChoiceImageEntryPrefab, imageAlbumList).GetComponent <MultipleChoiceImageEntry>();

        defaultToggleColor = albumEntry.toggle.image.color;
        albumEntry.toggle.SetIsOnWithoutNotify(correct);
        StartCoroutine(albumEntry.SetUrl(path));

        toggleGroup.RegisterToggle(albumEntry.toggle);
        albumEntry.toggle.group = toggleGroup;
        albumEntry.deleteButton.onClick.AddListener(() => DeleteAlbumEntry(albumEntry.gameObject));

        entries.Add(albumEntry);
    }
    void Update()
    {
        Debug.Log(answerAreas.Count);
        if (areaPicker != null && areaPicker.answered)
        {
            //NOTE(Simon): If areaPicker was not cancelled
            if (areaPicker.answerArea != null)
            {
                var filename = areaPicker.MakeMiniature(guid);
                var path     = Path.Combine(Application.persistentDataPath, guid.ToString(), SaveFile.miniaturesPath);
                var fullPath = Path.Combine(path, filename);

                var go    = editing ? editingGo : Instantiate(multipleChoiceAreaEntryPrefab, areaList);
                var entry = go.GetComponent <MultipleChoiceAreaEntry>();
                areaPicker.answerArea.miniatureName = filename;
                StartCoroutine(entry.SetArea(areaPicker.answerArea, 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;

                if (!editing)
                {
                    answerAreas.Add(areaPicker.answerArea);
                }
                defaultToggleColor = entry.toggle.image.color;
            }

            areaPicker.Dispose();
            Destroy(areaPicker.gameObject);
            resizePanel.SetActive(true);

            //NOTE(Simon): Reset the background color, in case it was red/invalid previously
            var background = areaList.parent.parent.GetComponent <Image>();
            background.color = defaultPanelColor;

            if (editing)
            {
                editing = false;
            }
        }
    }
    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);
    }