mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-20 23:57:49 +08:00
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using UniverseLib.Input;
|
|||
|
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(InputManager.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>();
|
|||
|
var popupGroup = popupLabel.gameObject.AddComponent<CanvasGroup>();
|
|||
|
popupGroup.blocksRaycasts = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|