mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-20 15:47:54 +08:00

- Use explicit type of var - Use 'new()' - Remove unnecessary usings - Sort usings - Apply formatting
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniverseLib.UI;
|
|
|
|
namespace UnityExplorer.UI
|
|
{
|
|
public static class Notification
|
|
{
|
|
private static Text popupLabel;
|
|
|
|
private static string _currentNotification;
|
|
private static float _timeOfLastNotification;
|
|
|
|
public static void Init()
|
|
{
|
|
ConstructUI();
|
|
}
|
|
|
|
public static void ShowMessage(string message)
|
|
{
|
|
popupLabel.text = message;
|
|
_currentNotification = message;
|
|
_timeOfLastNotification = Time.realtimeSinceStartup;
|
|
|
|
popupLabel.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(DisplayManager.MousePosition) + (Vector3.up * 25);
|
|
}
|
|
|
|
public static void Update()
|
|
{
|
|
if (_currentNotification != null)
|
|
{
|
|
if (Time.realtimeSinceStartup - _timeOfLastNotification > 2f)
|
|
{
|
|
_currentNotification = null;
|
|
popupLabel.text = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ConstructUI()
|
|
{
|
|
|
|
popupLabel = UIFactory.CreateLabel(UIManager.UIRoot, "ClipboardNotification", "", TextAnchor.MiddleCenter);
|
|
popupLabel.rectTransform.sizeDelta = new(500, 100);
|
|
popupLabel.gameObject.AddComponent<Outline>();
|
|
CanvasGroup popupGroup = popupLabel.gameObject.AddComponent<CanvasGroup>();
|
|
popupGroup.blocksRaycasts = false;
|
|
}
|
|
}
|
|
}
|