HKI Core
UISlidesController.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace HKI.Core.UI
4 {
8  public class UISlidesController : MonoBehaviour
9  {
10  // Public variables
11  [SerializeField] int StartSlideIndex = 0;
12 
13  [SerializeField] GameObject[] OpenSlideButtons;
14  [SerializeField] GameObject[] ActiveSlideIcons;
15  [SerializeField] GameObject[] Slides;
16 
17  // Start function
18  void Start()
19  {
20  if(OpenSlideButtons == null)
21  Debug.LogError("(UISlidesController) OpenSlideButtons is null!");
22  if(ActiveSlideIcons == null)
23  Debug.LogError("(UISlidesController) ActiveSlideIcons is null!");
24  if(Slides == null)
25  Debug.LogError("(UISlidesController) Slides is null!");
26  else if (OpenSlideButtons.Length != ActiveSlideIcons.Length || ActiveSlideIcons.Length != Slides.Length)
27  Debug.LogError("(UISlidesController) OpenSlideButtons, ActiveSlideIcons and Slides don't have the same size/length!");
28  else
29  OpenSlide(StartSlideIndex);
30  }
31 
32  // Interface functions
33  public void OpenSlide(int index)
34  {
35  if(index < 0 || index >= Slides.Length)
36  Debug.LogError("A slide with the index >" + index.ToString() + "< doesn't exists");
37  else
38  {
39  for(int i = 0; i < Slides.Length; i++)
40  {
41  if(i == index)
42  {
43  OpenSlideButtons[i].SetActive(false);
44  ActiveSlideIcons[i].SetActive(true);
45  Slides[i].SetActive(true);
46  }
47  else
48  {
49  OpenSlideButtons[i].SetActive(true);
50  ActiveSlideIcons[i].SetActive(false);
51  Slides[i].SetActive(false);
52  }
53  }
54  }
55  }
56  }
57 }
This MonoBehaviour is for showing one slide after another. One example would be a tabs window where s...