80 lines
1.7 KiB
C#
80 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public enum DisplayMessageType
|
|
{
|
|
DeviceLost,
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class DisplayMessage
|
|
{
|
|
public DisplayMessageType Type;
|
|
[TextArea]
|
|
public string Message;
|
|
public int Time;
|
|
}
|
|
|
|
public class UIInfoDisplay : MonoBehaviour
|
|
{
|
|
public static UIInfoDisplay Instance;
|
|
[SerializeField]
|
|
private RectTransform _spawnPoint;
|
|
|
|
[SerializeField]
|
|
private List<DisplayMessage> messages = new List<DisplayMessage>();
|
|
public UIDisplayMessage DisplayMessagePrefab;
|
|
|
|
private Dictionary<DisplayMessageType, UIDisplayMessage> showedMessages = new Dictionary<DisplayMessageType, UIDisplayMessage>();
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
InitMessages();
|
|
}
|
|
|
|
private void InitMessages()
|
|
{
|
|
foreach (var message in messages)
|
|
{
|
|
var newMessage = Instantiate(DisplayMessagePrefab, _spawnPoint);
|
|
newMessage.Init(message);
|
|
showedMessages.Add(message.Type, newMessage);
|
|
}
|
|
}
|
|
|
|
[ContextMenu("Debug show")]
|
|
private void DebugShow()
|
|
{
|
|
ShowInfo(DisplayMessageType.DeviceLost);
|
|
}
|
|
|
|
[ContextMenu("Debug hide")]
|
|
private void DebugHide()
|
|
{
|
|
HideInfo(DisplayMessageType.DeviceLost);
|
|
}
|
|
|
|
public void ShowInfo(DisplayMessageType type)
|
|
{
|
|
showedMessages[type].Show();
|
|
}
|
|
|
|
public void HideInfo(DisplayMessageType type)
|
|
{
|
|
showedMessages[type].Hide();
|
|
}
|
|
} |