video link- My Screencast
Code-
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class APITest : MonoBehaviour
{
public Vector2 scrollPosition = Vector2.zero;
private string message = "";
private Vector2 scrollView = Vector2.zero;
public Rect MainRect = new Rect(40, 20, 350, 125);
private void Start()
{
TextChat.messages = new ArrayList();
}
private void OnGUI()
{
MainRect = GUI.Window(0, MainRect, DoMainWindow, "Shout Box");
// GUILayout.BeginArea(new Rect(0, 30, Screen.width, Screen.height - 60));
// scrollView = GUILayout.BeginScrollView(scrollView);
// foreach(string c in TextChat.messages)
// {
// GUILayout.Label(c);
// }
// GUILayout.EndArea();
// GUILayout.EndScrollView();
// scrollView.y++;
// message = GUI.TextField(new Rect(0, Screen.height - 30, Screen.width - 50, 25), message);
// if (GUI.Button(new Rect(Screen.width - 50, Screen.height - 30, 50, 25), "Send"))
// {
// TextChat.cleaning = TextChat.Clean.none;
// GameObject.Find("Chat").GetComponent<TextChat>().sendMessage(message);
// message = "";
// }
}
void DoMainWindow(int windowID)
{
int y = 20;
Rect scrollRect = new Rect(10,10, MainRect.width - 30, MainRect.height - 60);
int height = TextChat.messages.Count * 20;
scrollPosition = GUI.BeginScrollView(scrollRect, scrollPosition, new Rect(0, 0, 0, height+20));
string output;
foreach(string c in TextChat.messages)
{
// GUILayout.Label(c);
output = c;
GUI.Button(new Rect(5, y, MainRect.height - 30, MainRect.width - 50),output, "label");
y+=20;
//Debug.Log (height+"="+TextChat.messages.Count+"*"+"20");
//scrollView.y++;
}
GUI.EndScrollView ();
//scrollPosition = new Vector2(0,height);
message = GUI.TextField(new Rect(5, MainRect.height - 30, MainRect.width - 50, 25), message);
if (GUI.Button(new Rect(MainRect.width - 45, MainRect.height - 30, 45, 25), "Send"))
{
TextChat.cleaning = TextChat.Clean.none;
GameObject.Find("Chat").GetComponent<TextChat>().sendMessage(message);
message = "";
}
GUI.DragWindow();
}
}