EncyclopediaController.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.UI.InteractionHandler;
  6. namespace KairoEngine.UI.Encyclopedia
  7. {
  8. [HideMonoScript]
  9. public class EncyclopediaController : MonoBehaviour, IClickHandler
  10. {
  11. [ShowInInspector, HorizontalGroup("IndexLine", 0.7f), LabelText("Index")] public int menuIndex;
  12. [ShowInInspector, HorizontalGroup("IndexLine", 0.3f), HideLabel] public int subMenuIndex;
  13. public EncyclopediaUi encyclopediaUi;
  14. public GameObject categoryButtomPrefab;
  15. public List<EncyclopediaCategory> categories = new List<EncyclopediaCategory>();
  16. [Button("Build Menu"), ButtonGroup("Buttons")]
  17. public void BuildMenu()
  18. {
  19. if(encyclopediaUi != null) encyclopediaUi.Populate();
  20. else Debug.LogError("Missing Encyclopedia UI in Encyclopedia Controller", this.gameObject);
  21. }
  22. public void OnClick(string id)
  23. {
  24. for (int i = 0; i < categories.Count; i++)
  25. {
  26. if(id == categories[i].id)
  27. {
  28. menuIndex = i;
  29. Navigate();
  30. return;
  31. }
  32. var articles = categories[i].GetArticles();
  33. for (int a = 0; a < articles.Count; a++)
  34. {
  35. if(id == articles[a].id)
  36. {
  37. menuIndex = i;
  38. subMenuIndex = a;
  39. Navigate();
  40. return;
  41. }
  42. }
  43. }
  44. }
  45. [Button("Navigate"), ButtonGroup("Buttons")]
  46. public void Navigate()
  47. {
  48. if(encyclopediaUi != null) encyclopediaUi.Navigate();
  49. }
  50. }
  51. }