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 messages = new List(); public UIDisplayMessage DisplayMessagePrefab; private Dictionary showedMessages = new Dictionary(); 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(); } }