SlideshowController.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Sirenix.OdinInspector;
  6. using KairoEngine.Core.GameActions;
  7. namespace KairoEngine.UI
  8. {
  9. [HideMonoScript]
  10. public class SlideshowController : MonoBehaviour
  11. {
  12. [SerializeField, ShowInInspector] private List<SlideData> slides = new List<SlideData>();
  13. public bool executeOnStart = true;
  14. [HideLabel, InlineProperty, FoldoutGroup("OnEnd")] public GameActionsController endActionController = new GameActionsController();
  15. private bool started = false;
  16. private bool finished = false;
  17. private int slideIndex = 0;
  18. private void Start()
  19. {
  20. for (int i = 0; i < slides.Count; i++) slides[i].Hide();
  21. if(executeOnStart) started = true;
  22. }
  23. private void Update()
  24. {
  25. if(started == false) return;
  26. if(finished == true) return;
  27. if(slideIndex >= slides.Count)
  28. {
  29. endActionController.Start();
  30. finished = true;
  31. return;
  32. }
  33. var done = slides[slideIndex].UpdateSlide();
  34. if(done)
  35. {
  36. slides[slideIndex].Hide();
  37. slideIndex += 1;
  38. }
  39. }
  40. public void StartSlideShow() => started = true;
  41. }
  42. }