2023-09-04 12:48:24 +03:00
|
|
|
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]
|
2023-09-05 17:38:11 +03:00
|
|
|
private RectTransform _spawnPoint;
|
|
|
|
|
2023-09-04 12:48:24 +03:00
|
|
|
[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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 17:38:11 +03:00
|
|
|
private void Start()
|
2023-09-04 12:48:24 +03:00
|
|
|
{
|
2023-09-05 17:38:11 +03:00
|
|
|
InitMessages();
|
|
|
|
}
|
2023-09-04 12:48:24 +03:00
|
|
|
|
2023-09-05 17:38:11 +03:00
|
|
|
private void InitMessages()
|
|
|
|
{
|
|
|
|
foreach (var message in messages)
|
|
|
|
{
|
|
|
|
var newMessage = Instantiate(DisplayMessagePrefab, _spawnPoint);
|
|
|
|
newMessage.Init(message);
|
|
|
|
showedMessages.Add(message.Type, newMessage);
|
2023-09-04 12:48:24 +03:00
|
|
|
}
|
2023-09-05 17:38:11 +03:00
|
|
|
}
|
2023-09-04 12:48:24 +03:00
|
|
|
|
2023-09-05 17:38:11 +03:00
|
|
|
[ContextMenu("Debug show")]
|
|
|
|
private void DebugShow()
|
|
|
|
{
|
|
|
|
ShowInfo(DisplayMessageType.DeviceLost);
|
2023-09-04 12:48:24 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 17:38:11 +03:00
|
|
|
[ContextMenu("Debug hide")]
|
|
|
|
private void DebugHide()
|
2023-09-04 12:48:24 +03:00
|
|
|
{
|
2023-09-05 17:38:11 +03:00
|
|
|
HideInfo(DisplayMessageType.DeviceLost);
|
|
|
|
}
|
2023-09-04 12:48:24 +03:00
|
|
|
|
2023-09-05 17:38:11 +03:00
|
|
|
public void ShowInfo(DisplayMessageType type)
|
|
|
|
{
|
|
|
|
showedMessages[type].Show();
|
2023-09-04 12:48:24 +03:00
|
|
|
}
|
2023-09-05 17:38:11 +03:00
|
|
|
|
|
|
|
public void HideInfo(DisplayMessageType type)
|
|
|
|
{
|
|
|
|
showedMessages[type].Hide();
|
|
|
|
}
|
|
|
|
}
|