2023-10-03 17:31:06 +03:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class UIFader : MonoBehaviour
|
|
|
|
{
|
2023-10-04 12:49:59 +03:00
|
|
|
public float FadeTime;
|
2023-10-03 17:31:06 +03:00
|
|
|
|
|
|
|
private CanvasGroup canvasGroup;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool isShow = true;
|
|
|
|
|
2023-10-11 15:44:05 +03:00
|
|
|
public bool HideOnStart = false;
|
|
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
if (HideOnStart)
|
|
|
|
HidePanel();
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:40:12 +03:00
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
LeanTween.cancel(gameObject);
|
|
|
|
}
|
|
|
|
|
2023-10-03 17:31:06 +03:00
|
|
|
public void ShowPanel()
|
|
|
|
{
|
2023-10-19 12:40:12 +03:00
|
|
|
if (canvasGroup == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//LeanTween.value(0, 1, FadeTime).setOnUpdate((float x) =>
|
|
|
|
//{
|
|
|
|
// canvasGroup.alpha = x;
|
|
|
|
//});
|
|
|
|
|
|
|
|
canvasGroup.alpha = 1;
|
2023-10-03 17:31:06 +03:00
|
|
|
canvasGroup.blocksRaycasts = true;
|
|
|
|
isShow = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void HidePanel()
|
|
|
|
{
|
2023-10-19 12:40:12 +03:00
|
|
|
if (canvasGroup == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//LeanTween.value(1, 0, FadeTime).setOnUpdate((float x) =>
|
|
|
|
//{
|
|
|
|
// canvasGroup.alpha = x;
|
|
|
|
//});
|
2023-10-03 17:31:06 +03:00
|
|
|
|
2023-10-19 12:40:12 +03:00
|
|
|
canvasGroup.alpha = 0;
|
2023-10-03 17:31:06 +03:00
|
|
|
canvasGroup.blocksRaycasts = false;
|
|
|
|
isShow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Toggle()
|
|
|
|
{
|
|
|
|
if (isShow)
|
|
|
|
HidePanel();
|
|
|
|
else
|
|
|
|
ShowPanel();
|
|
|
|
}
|
|
|
|
}
|