CategorySelection.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. [SerializeField] readonly Text CategoryNameText;
  8. [SerializeField] readonly Toggle selectionToggle;
  9. private int questionCount;
  10. private Boolean selected;
  11. public int QuestionCount { get => questionCount; set => questionCount = value; }
  12. public bool Selected { get => selected; set => selected = value; }
  13. // Start is called before the first frame update
  14. void Start() {
  15. selectionToggle.onValueChanged.AddListener(SelectionChanged);
  16. }
  17. private void SelectionChanged(bool arg0) {
  18. Selected = arg0;
  19. }
  20. // Update is called once per frame
  21. void Update() {
  22. }
  23. internal void SetCategoryText(string categoryName, int questionCount) {
  24. CategoryNameText.text = categoryName + " (" + questionCount + ")";
  25. }
  26. internal void SetSelected(bool selected) {
  27. selectionToggle.SetIsOnWithoutNotify(selected);
  28. }
  29. public string getCategoryName() {
  30. string catText = CategoryNameText.text;
  31. return catText.Substring(0, catText.IndexOf('(') - 1);
  32. }
  33. public bool isSelected() {
  34. return selectionToggle.isOn;
  35. }
  36. }