|
|
|
//FadeSystem v1.1_2
|
|
|
|
using UnityEngine;
|
|
|
|
using DG.Tweening;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using HGR.Core.Singletons;
|
|
|
|
|
|
|
|
public delegate void Callback();
|
|
|
|
|
|
|
|
[HideMonoScript]
|
|
|
|
public class FadeSystem : Singleton<FadeSystem>
|
|
|
|
{
|
|
|
|
//===================================================
|
|
|
|
// FIELDS
|
|
|
|
//===================================================
|
|
|
|
[Title("FADE SYSTEM", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
[SerializeField] Image Panel = null;
|
|
|
|
[Range(0.2f, 1.0f)]
|
|
|
|
[SerializeField] float FadeSpeed = 1.0f;
|
|
|
|
|
|
|
|
//===================================================
|
|
|
|
// METHODS
|
|
|
|
//===================================================
|
|
|
|
internal override void Init()
|
|
|
|
{
|
|
|
|
base.Init();
|
|
|
|
|
|
|
|
if(InstanceNotSelf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!Panel)
|
|
|
|
Panel = GetComponentInChildren<Image>();
|
|
|
|
Panel.color = new Color(Panel.color.r, Panel.color.g, Panel.color.b, 0f);
|
|
|
|
// GameLog.InitMessage<FadeSystem>();
|
|
|
|
}//Awake() end
|
|
|
|
|
|
|
|
public void Splash()
|
|
|
|
{
|
|
|
|
Panel.color = new Color(Panel.color.r, Panel.color.g, Panel.color.b, 1f);
|
|
|
|
// Panel.DOFade(0.0f, FadeSpeed).SetDelay(0.25f).OnComplete(()=>Panel.raycastTarget = false);
|
|
|
|
}//Splash() end
|
|
|
|
|
|
|
|
public void Fade(GameObject TurnOff = null, GameObject TurnOn = null)
|
|
|
|
{
|
|
|
|
Panel.raycastTarget = true;
|
|
|
|
Panel.DOFade(1.0f, FadeSpeed).OnComplete(()=>
|
|
|
|
{
|
|
|
|
TurnOff?.SetActive(false);
|
|
|
|
TurnOn?.SetActive(true);
|
|
|
|
Panel.DOFade(0.0f, FadeSpeed).OnComplete(()=>Panel.raycastTarget = false);
|
|
|
|
}
|
|
|
|
);//Tween end
|
|
|
|
}//Fade() end
|
|
|
|
|
|
|
|
public void Fade(Callback Action = null, float interval = 0.5f)
|
|
|
|
{
|
|
|
|
Panel.raycastTarget = true;
|
|
|
|
Sequence mySequence = DOTween.Sequence();
|
|
|
|
mySequence.Append(Panel.DOFade(1.0f, FadeSpeed).OnComplete(()=>Action?.Invoke()));
|
|
|
|
mySequence.AppendInterval(interval);
|
|
|
|
mySequence.Append(Panel.DOFade(0.0f, FadeSpeed).OnComplete(()=>Panel.raycastTarget = false));
|
|
|
|
DOTween.Kill(mySequence);
|
|
|
|
}//Fade() end
|
|
|
|
|
|
|
|
public void FadeIn(Callback Action)
|
|
|
|
{
|
|
|
|
Panel.raycastTarget = true;
|
|
|
|
Panel.DOFade(1.0f, FadeSpeed).OnComplete(()=>Action?.Invoke());
|
|
|
|
}//FadeIn() end
|
|
|
|
|
|
|
|
public void FadeOut(Callback Action = null)
|
|
|
|
{
|
|
|
|
Panel.DOFade(0.0f, FadeSpeed).OnComplete(()=>
|
|
|
|
{
|
|
|
|
Action?.Invoke();
|
|
|
|
Panel.raycastTarget = false;
|
|
|
|
}//Callbacks
|
|
|
|
);
|
|
|
|
}//FadeOut() end
|
|
|
|
|
|
|
|
}//class end
|