HKI Core
SplashScreenManager.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.SceneManagement;
3 using System.Collections;
4 using HKI.Core.Scenes;
5 
6 namespace HKI.Core.Init
7 {
11  public class SplashScreenManager : MonoBehaviour
12  {
13  // Classes
17  [System.Serializable]
18  public class SplashScreen
19  {
20  // Public Variables
21  [SerializeField] GameObject SplashScreenGO = null;
22  [SerializeField] float DurationTime = 5.0f;
23 
24  // Getter
25  public GameObject GetSplashScrenGO { get { return SplashScreenGO; } }
26  public float GetDurationTime { get { return DurationTime; } }
27  }
28 
29  // Public variables
30  [SerializeField] [Scene] string MainMenuScene = "";
31  [SerializeField] float MinSplashScreenTime = 3.0f;
32  [SerializeField] SplashScreen[] SplashScreens;
33 
34  // Start function
35  void Start()
36  {
37  StartCoroutine(HandleSplashScreens());
38  }
39 
40  // Coroutine functions
41  IEnumerator HandleSplashScreens()
42  {
43  if(SplashScreens == null || SplashScreens.Length == 0)
44  yield return new WaitForSecondsRealtime(MinSplashScreenTime);
45  else
46  {
47  float remainingMinSplashScreenTime = MinSplashScreenTime;
48  float remainingDurationTime = 0.0f;
49 
50  for(int i = 0; i < SplashScreens.Length; i++)
51  {
52  if (SplashScreens[i].GetSplashScrenGO != null)
53  SplashScreens[i].GetSplashScrenGO.SetActive(false);
54  }
55 
56  for (int i = 0; i < SplashScreens.Length; i++)
57  {
58  remainingDurationTime = SplashScreens[i].GetDurationTime;
59 
60  if(SplashScreens[i].GetSplashScrenGO != null)
61  SplashScreens[i].GetSplashScrenGO.SetActive(true);
62 
63  while(remainingDurationTime >= 0.0f)
64  {
65  remainingMinSplashScreenTime -= Time.deltaTime;
66  remainingDurationTime -= Time.deltaTime;
67 
68  if(remainingMinSplashScreenTime <= 0.0f && Input.GetKeyDown(KeyCode.Escape))
69  {
70  SceneManager.LoadScene(MainMenuScene);
71  yield break;
72  }
73 
74  yield return null;
75  }
76 
77  if(SplashScreens[i].GetSplashScrenGO != null && i != SplashScreens.Length - 1)
78  SplashScreens[i].GetSplashScrenGO.SetActive(false);
79  }
80  }
81 
82  SceneManager.LoadScene(MainMenuScene);
83  }
84  }
85 }
This SplashScreenManager enables slides for a duration of time and after all slide have been shown it...
This class holds all the data of a slide that is shown by the SplashScreenManager ...