UniversalViewer/Assets/Scripts/SharedBasic/Error.cs

31 lines
902 B
C#
Raw Normal View History

2024-04-21 22:38:26 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Error : MonoBehaviour
{
public static GameObject ErrorText;
public static GameObject CanvasContent;
private void Awake()
{
ErrorText = Resources.Load(Strings.ErrorTextPrefab) as GameObject;
CanvasContent = GameObject.Find(Strings.ErrorContent);
}
public static void Log(Color color, string message, float time = 5)
{
Log(message, color, time);
}
public static void Log(string message, Color color, float time = 5)
{
Debug.Log(message);
if (CanvasContent == null) return;
Text text = Instantiate(ErrorText, CanvasContent.transform).GetComponent<Text>();
text.text = message;
text.color = color;
Destroy(text.gameObject, CanvasContent.transform.childCount+1 * time);
}
}