2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

62 lines
2.0 KiB

using UnityEngine;
namespace Unity.FPS.UI
{
public class NotificationToast : MonoBehaviour
{
[Tooltip("Text content that will display the notification text")]
public TMPro.TextMeshProUGUI TextContent;
[Tooltip("Canvas used to fade in and out the content")]
public CanvasGroup CanvasGroup;
[Tooltip("How long it will stay visible")]
public float VisibleDuration;
[Tooltip("Duration of the fade in")]
public float FadeInDuration = 0.5f;
[Tooltip("Duration of the fade out")]
public float FadeOutDuration = 2f;
public bool Initialized { get; private set; }
float m_InitTime;
public float TotalRunTime => VisibleDuration + FadeInDuration + FadeOutDuration;
public void Initialize(string text)
{
TextContent.text = text;
m_InitTime = Time.time;
// start the fade out
Initialized = true;
}
void Update()
{
if (Initialized)
{
float timeSinceInit = Time.time - m_InitTime;
if (timeSinceInit < FadeInDuration)
{
// fade in
CanvasGroup.alpha = timeSinceInit / FadeInDuration;
}
else if (timeSinceInit < FadeInDuration + VisibleDuration)
{
// stay visible
CanvasGroup.alpha = 1f;
}
else if (timeSinceInit < FadeInDuration + VisibleDuration + FadeOutDuration)
{
// fade out
CanvasGroup.alpha = 1 - (timeSinceInit - FadeInDuration - VisibleDuration) / FadeOutDuration;
}
else
{
CanvasGroup.alpha = 0f;
// fade out over, destroy the object
Destroy(gameObject);
}
}
}
}
}