Witam,napisałem prosty skrypt na czat i mam problem ze Scrollowaniem tekstu.
Próbowałem różncych metod. Próbowałem dodać Scrollbar,próbowałem skorzystać z metody GUILayout.BeginScrollView() ale nic nie działało prawidłowo. Chciałbym to zrobić bez zbytniego "niszczenia" poniższego skryptu:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Chat : MonoBehaviour
{
private List<string>ChatHistory = new List<string>();
public GUISkin myskin;
public float vSbarValue;
private Rect windowRect = new Rect(0,Screen.height - 400, Screen.width, 400);
private string messBox = "", messageToSend = "", user = "";
private int ID;
private Inventory MyInventory = new Inventory ();
private PlayerSkin MyPlayerSkin = new PlayerSkin();
private bool Send;
private bool AdminMode;
private Texture2D otherSkin;
private Sprite mysprite;
private bool ChatVisible;
Vector2 scrollPosition = Vector2.zero;
void Start()
{
user = PlayerEssentials.PlayerName;
//otherSkin = Resources.Load<Texture2D> ("Skins/PlayerBase");
}
private void OnGUI()
{
GUI.skin = myskin;
if (NetworkPeerType.Disconnected != Network.peerType && ChatVisible)
{
windowRect = GUI.Window (1, windowRect, windowFunc, "", myskin.GetStyle ("ChatWindowStyle"));
}
}
void Update()
{
if (Input.GetKeyDown (KeyCode.T)) //dodanie else sprawi jednorazowe działanie;
{
ChatVisible = !ChatVisible;
}
}
[RPC]
private void windowFunc(int id)
{
GUILayout.Box(messBox,GUILayout.Height(350));
//vSbarValue = GUI.VerticalScrollbar(new Rect(Screen.width - 20, 5, 100, 350), vSbarValue, 1.0F, 10.0F, 0.0F);
GUILayout.BeginHorizontal();
messageToSend = GUILayout.TextField(messageToSend);
GUILayout.EndVertical ();
GUILayout.BeginVertical ();
if (Input.GetKeyDown(KeyCode.T) || Input.GetKeyDown(KeyCode.F))
{
if(user != "")
{
networkView.RPC("SendMsg", RPCMode.All,"<color=#ff8400>" + "Emil nie mógł znaleźć tej komendy!" + "</color>" + "\n");
messageToSend = "";
}
else
{
if(messageToSend != "")
{
networkView.RPC("SendMsg", RPCMode.All, user + ": " + "<color=#00a2ff>" + messageToSend + "</color>" + "\n");
messageToSend = "";
}
}
}
if(messageToSend == "")
{
Send = false;
}
else
{
Send = true;
}
ChatHistory.Add(messageToSend);
}
GUILayout.EndVertical();
}
[RPC]
private void SendMsg(string mess)
{
messBox += mess;
}
}