2025-06-06 10:14:55 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
using UnityEngine;
|
2025-07-21 05:42:20 -04:00
|
|
|
using UnityEngine.Events;
|
2025-06-06 10:14:55 -04:00
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Ichni.UI
|
|
|
|
|
{
|
|
|
|
|
public class UIPageBase : SerializedMonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public CanvasGroup mainCanvasGroup;
|
2025-08-11 14:04:06 -04:00
|
|
|
public UnityAction fadeInStartAction;
|
|
|
|
|
public UnityAction fadeInFinishAction;
|
|
|
|
|
public UnityAction fadeOutAction;
|
2025-06-06 10:14:55 -04:00
|
|
|
|
2025-08-11 14:04:06 -04:00
|
|
|
protected virtual void Awake()
|
2025-06-06 10:14:55 -04:00
|
|
|
{
|
|
|
|
|
CanvasGroup group = GetComponent<CanvasGroup>();
|
|
|
|
|
if (group != null)
|
|
|
|
|
{
|
|
|
|
|
mainCanvasGroup ??= group;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-11 14:04:06 -04:00
|
|
|
public virtual void FadeIn(float duration = 0.5f, bool ignoreTimeScale = false, UnityAction action = null)
|
2025-06-06 10:14:55 -04:00
|
|
|
{
|
|
|
|
|
mainCanvasGroup.gameObject.SetActive(true);
|
2025-08-11 14:04:06 -04:00
|
|
|
fadeInStartAction?.Invoke();
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
Tweener fade = mainCanvasGroup.DOFade(1f, duration).OnComplete(() =>
|
2025-06-06 10:14:55 -04:00
|
|
|
{
|
|
|
|
|
mainCanvasGroup.interactable = true;
|
|
|
|
|
mainCanvasGroup.blocksRaycasts = true;
|
2025-08-11 14:04:06 -04:00
|
|
|
fadeInFinishAction?.Invoke();
|
2025-07-21 05:42:20 -04:00
|
|
|
action?.Invoke();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (ignoreTimeScale)
|
|
|
|
|
{
|
|
|
|
|
fade.SetUpdate(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fade.Play();
|
2025-06-06 10:14:55 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-11 14:04:06 -04:00
|
|
|
public virtual void FadeOut(float duration = 0.5f, bool ignoreTimeScale = false, UnityAction action = null)
|
2025-06-06 10:14:55 -04:00
|
|
|
{
|
|
|
|
|
mainCanvasGroup.interactable = false;
|
|
|
|
|
mainCanvasGroup.blocksRaycasts = false;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
Tweener fade = mainCanvasGroup.DOFade(0f, duration).OnComplete(() =>
|
2025-06-06 10:14:55 -04:00
|
|
|
{
|
2025-08-11 14:04:06 -04:00
|
|
|
fadeOutAction?.Invoke();
|
2025-07-21 05:42:20 -04:00
|
|
|
action?.Invoke();
|
2025-06-06 10:14:55 -04:00
|
|
|
mainCanvasGroup.gameObject.SetActive(false);
|
2025-07-21 05:42:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (ignoreTimeScale)
|
|
|
|
|
{
|
|
|
|
|
fade.SetUpdate(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fade.Play();
|
2025-06-06 10:14:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|