63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace Ichni.UI
|
|
{
|
|
public class UIPageBase : SerializedMonoBehaviour
|
|
{
|
|
public CanvasGroup mainCanvasGroup;
|
|
|
|
private void Awake()
|
|
{
|
|
CanvasGroup group = GetComponent<CanvasGroup>();
|
|
if (group != null)
|
|
{
|
|
mainCanvasGroup ??= group;
|
|
}
|
|
}
|
|
|
|
public void FadeIn(float duration = 0.5f, bool ignoreTimeScale = false, UnityAction action = null)
|
|
{
|
|
mainCanvasGroup.gameObject.SetActive(true);
|
|
|
|
Tweener fade = mainCanvasGroup.DOFade(1f, duration).OnComplete(() =>
|
|
{
|
|
mainCanvasGroup.interactable = true;
|
|
mainCanvasGroup.blocksRaycasts = true;
|
|
action?.Invoke();
|
|
});
|
|
|
|
if (ignoreTimeScale)
|
|
{
|
|
fade.SetUpdate(true);
|
|
}
|
|
|
|
fade.Play();
|
|
}
|
|
|
|
public void FadeOut(float duration = 0.5f, bool ignoreTimeScale = false, UnityAction action = null)
|
|
{
|
|
mainCanvasGroup.interactable = false;
|
|
mainCanvasGroup.blocksRaycasts = false;
|
|
|
|
Tweener fade = mainCanvasGroup.DOFade(0f, duration).OnComplete(() =>
|
|
{
|
|
action?.Invoke();
|
|
mainCanvasGroup.gameObject.SetActive(false);
|
|
});
|
|
|
|
if (ignoreTimeScale)
|
|
{
|
|
fade.SetUpdate(true);
|
|
}
|
|
|
|
fade.Play();
|
|
}
|
|
}
|
|
} |