CategorySelection.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class CategorySelection : MonoBehaviour
  7. {
  8. [SerializeField] Text CategoryNameText;
  9. [SerializeField] Toggle selectionToggle;
  10. private int questionCount;
  11. private Boolean selected;
  12. public int QuestionCount { get => questionCount; set => questionCount = value; }
  13. public bool Selected { get => selected; set => selected = value; }
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. selectionToggle.onValueChanged.AddListener(SelectionChanged);
  18. }
  19. private void SelectionChanged(bool arg0) {
  20. Selected = arg0;
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. }
  26. internal void SetCategoryText(string categoryName, int questionCount) {
  27. CategoryNameText.text = categoryName + " (" + questionCount + ")";
  28. }
  29. internal void SetSelected(bool selected) {
  30. selectionToggle.SetIsOnWithoutNotify(selected);
  31. }
  32. public string getCategoryName() {
  33. string catText = CategoryNameText.text;
  34. return catText.Substring(0, catText.IndexOf('(') - 1);
  35. }
  36. public bool isSelected() {
  37. return selectionToggle.isOn;
  38. }
  39. }