FadeInManager.cs 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using DG.Tweening;
  5. /// <summary>
  6. /// This component is responsible for fading in the main game scene, after loading has completed.
  7. /// </summary>
  8. public class FadeInManager : MonoBehaviour
  9. {
  10. public static FadeInManager Instance;
  11. public GameObject uiRoot;
  12. public GameObject backgroundManager;
  13. public GameObject[] objectsToEnable;
  14. public Image sceneFaderRenderer;
  15. public bool runFromMainScene;
  16. void Awake()
  17. {
  18. OnSkinApplied();
  19. uiRoot.SetActive(true);
  20. backgroundManager.SetActive(true);
  21. foreach (GameObject go in objectsToEnable)
  22. {
  23. go.SetActive(true);
  24. }
  25. Instance = this;
  26. }
  27. void OnSkinApplied()
  28. {
  29. sceneFaderRenderer.DOFade(0f, 0.5f);
  30. OniTweenFadeInComplete();
  31. }
  32. void OniTweenFadeInComplete()
  33. {
  34. Destroy(gameObject);
  35. Destroy(sceneFaderRenderer.gameObject);
  36. }
  37. }