editing scenes and UI
This commit is contained in:
@@ -3,11 +3,14 @@ using System.Collections.Generic;
|
||||
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class UICanvas : MonoBehaviour
|
||||
{
|
||||
CanvasGroup canvasGroup;
|
||||
public UnityEvent OnHide;
|
||||
[SerializeField] float duration;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -16,19 +19,24 @@ public class UICanvas : MonoBehaviour
|
||||
|
||||
public void Show()
|
||||
{
|
||||
canvasGroup.DOFade(1, .4f);
|
||||
canvasGroup.DOFade(1, duration);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
canvasGroup.DOFade(0, .4f);
|
||||
gameObject.SetActive(false);
|
||||
canvasGroup.DOFade(0, duration)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
OnHide?.Invoke();
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(canvasGroup == null)
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
canvasGroup.alpha = 0;
|
||||
Show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user