using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; namespace SimpleInventorySystem { public class DisplayMessageSystem : MonoBehaviour { public static DisplayMessageSystem instance; public DisplayMessage[] displayMessages; protected InventorySystem.States currentState; [HideInInspector] public string NameOfItemInWorldWithFocus; private void Awake() { instance = this; } // Start is called before the first frame update void Start() { foreach (DisplayMessage displayMessage in displayMessages) { TextMeshProUGUI message = displayMessage.message; if (displayMessage != null && message != null) { string text = message.text; if (text.Contains("{key:interactKey}")) message.text = message.text.Replace("{key:interactKey}", "[ " + InventorySystem.instance.interactKey.ToString() + " ]"); } displayMessage.SetOriginalMessage(); } } // Update is called once per frame void Update() { if(currentState != InventorySystem.instance.CurrentState) { currentState = InventorySystem.instance.CurrentState; foreach (DisplayMessage displayMessage in displayMessages) { if (currentState == InventorySystem.States.Undefined) { displayMessage.message.gameObject.SetActive(false); } else if (currentState == displayMessage.displayState) { displayMessage.message.gameObject.SetActive(true); } else { displayMessage.message.gameObject.SetActive(false); } } } //if(NameOfItemInWorldWithFocus != ) foreach (DisplayMessage displayMessage in displayMessages) { TextMeshProUGUI message = displayMessage.message; if (displayMessage != null && message != null && displayMessage.originalMessage.Contains("{item:name}")) { message.text = displayMessage.originalMessage.Replace("{item:name}", NameOfItemInWorldWithFocus); } } } } [Serializable] public class DisplayMessage { public TextMeshProUGUI message; public InventorySystem.States displayState; [HideInInspector] public string originalMessage; public DisplayMessage() { } public void SetOriginalMessage() { originalMessage = message.text; } } }