I’m trying to make a ‘TextWindow’ that holds messages that the Application sends to it. The problem is that I have no idea on how to do this.
I want to do something like, in C#,
TextWindow.NewLine("This will be displayed in the TextWindow");
Would I just create a new script called “TextWindow” and set it up something like this?
using UnityEngine;
using System.Collections;
public class TextWindow : MonoBehaviour
{
public TextWindow(Rect Size, string WindowName)
{
GUI.Box(new Rect(Size), WindowName);
}
public NewLine(string Text)
{
GUI.Label(new Rect(Rect), Text);
}
}
Then call it using,
TextWindow tWindow = new TextWindow(Size);
Size of course being a Rect.
This is a basic concept on how I want it to look in the end.
public static class MyConsole{
private static List< string > messages;
private static Vector2 viewPoint;
public static void DrawConsole(Rect area){
GUILayout.BeginArea(area);
viewPoint = GUILayout.BeginScrollView(viewPoint);
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
//print each string in messages here
//now close all the above areas
}
public static void NewMessage(string message){
messages.Add(message);
viewPoint = Vector2.one;
}
}
Now, in an OnGUI, to draw this, you use MyConsole.DrawConsole(area); and to add messages, MyConsole.NewMessage(message);
If you, for some reason need multiple consoles/textwindows, the same idea applies, you just need to remove the static, and keep track of the references.