Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using System.Diagnostics;
- public class UpdateDisplay : MonoBehaviour
- {
- // Start is called before the first frame update
- TMP_Text thisText;
- [SerializeField] InventoryObject inventoryToRead;
- void Start()
- {
- PlayerInventory.OnItemPickedUp += UpdateDisplayText;
- thisText = GetComponent<TMP_Text>();
- }
- // Update is called once per frame
- void Update()
- {
- }
- void UpdateDisplayText(InventoryObject _inventory)
- {
- UnityEngine.Debug.Log(GetClassAndMethod());
- UnityEngine.Debug.Log("UpdateDisplayText() called!");
- thisText.text = ProcessInventoryToSingleString(_inventory);
- }
- string[] GenerateArray(InventoryObject _inventory)
- {
- string[] arrayToReturn = new string[_inventory.Container.Count];
- for (int i = 0; i < _inventory.Container.Count; i++)
- {
- arrayToReturn[i] = $"{_inventory.Container[i].amount}x {_inventory.Container[i].itemContained.itemName} \n";
- }
- return arrayToReturn;
- }
- string MakeArrayOneString(string[] stringArray)
- {
- string wholeText = "";
- foreach(string s in stringArray)
- {
- wholeText += s;
- }
- return wholeText;
- }
- string ProcessInventoryToSingleString(InventoryObject _inventory)
- {
- string output = MakeArrayOneString(GenerateArray(_inventory));
- return output;
- }
- private void OnApplicationQuit()
- {
- PlayerInventory.OnItemPickedUp -= UpdateDisplayText;
- }
- private static string GetClassAndMethod()
- {
- StackTrace stackTrace = new StackTrace();
- StackFrame frame = stackTrace.GetFrame(2); // get the frame of the most recent caller
- string s = frame.GetMethod().DeclaringType.Name + "::" + frame.GetMethod().Name + "(";
- foreach (System.Reflection.ParameterInfo pi in frame.GetMethod().GetParameters())
- {
- s += pi.ParameterType.ToString() + " " + pi.Name + ",";
- }
- s += ")";
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement