You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/ScreenFader.cs

88 lines
1.6 KiB
C#

2 months ago
/*
http://www.cgsoso.com/forum-211-1.html
CG Unity3d Unity3d VIP
CGSOSO CG
daily assets update for try.
U should buy the asset from home store if u use it in your project!
*/
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class ScreenFader : MonoBehaviour
{
public static ScreenFader instance;
public const float DURATION = 0.37f;
private void Awake()
{
instance = this;
}
private void Start()
{
2 months ago
// GTil.Init(this);
2 months ago
}
public void FadeOut(Action onComplete)
{
GetComponent<Animator>().SetTrigger("fade_out");
GetComponent<Image>().enabled = true;
Timer.Schedule(this, 0.37f, delegate
{
if (onComplete != null)
{
onComplete();
}
});
}
public void FadeIn(Action onComplete)
{
GetComponent<Animator>().SetTrigger("fade_in");
Timer.Schedule(this, 0.37f, delegate
{
GetComponent<Image>().enabled = false;
if (onComplete != null)
{
onComplete();
}
});
}
public void GotoScene(int sceneIndex)
{
FadeOut(delegate
{
CUtils.LoadScene(sceneIndex);
});
}
private void OnEnable()
{
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}
private void OnDisable()
{
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
}
private void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
{
if (GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName("ScreenFader_Out"))
{
FadeIn(null);
}
}
}