- Home /
Chat window not displayed
Hi, when i am trying to click a chat button, chatwindow(function DrawLobbyGUI())is not displayed properly. But with out chat button it's working fine.....please help
void OnGUI() {
if (!started) return;
GUI.skin = gSkin;
ShowChatGUI();
//DrawLobbyGUI();
}
public void ShowChatGUI(){
if (GUILayout.Button("chat"))
{
DrawLobbyGUI();
//Debug.Log("HAI");
}
}
public void DrawLobbyGUI() {
Room currentActiveRoom = smartFox.LastJoinedRoom;
if ( currentActiveRoom == null ) {
// Wait until active room has been set up in the API before drawing anything
return;
}
//Debug.Log("lobby");
float chatPanelWidth = Screen.width*1/4;
float chatPanelHeight = Screen.height/2+20;
......................................
float userPanelWidth = roomPanelWidth;
...........................
............................................
GUILayout.BeginArea(new Rect(userPanelPosX, userPanelPosY, userPanelWidth, userPanelHeight));
GUILayout.Box ("Users", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUILayout.BeginVertical();
GUILayout.BeginArea(new Rect(20, 25, userPanelWidth-40, userPanelHeight-40), GUI.skin.customStyles[0]);
//userScrollPosition = GUILayout.BeginScrollView (userScrollPosition);
userScrollPosition = GUILayout.BeginScrollView (userScrollPosition, GUILayout.Width (150), GUILayout.Height (160));
foreach (User user in currentActiveRoom.UserList) {
GUILayout.Label(user.Name);
}
GUILayout.EndScrollView ();
GUILayout.EndArea ();
// Current user info
GUILayout.BeginArea(new Rect(20, 25 + userPanelHeight - 70, userPanelWidth-40, 40));
GUILayout.BeginHorizontal();
GUILayout.Label("Logged in as " + smartFox.MySelf.Name);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Logout")) {
smartFox.Send( new LogoutRequest() );
}
GUILayout.EndHorizontal();
GUILayout.EndArea ();
GUILayout.EndVertical();
GUILayout.EndArea ();
// Room chat window
chatWindow.Draw(chatPanelPosX, chatPanelPosY, chatPanelWidth, chatPanelHeight);
}
i see that there is a difference in the call order of ShowChatGUI() and DrawLobbyGUI() when you use button.
Reading the code closer it is not the call order that is the problem, it is that when using the button, DrawLobbyGUI() only gets called when button is clicked.
Answer by Linus · Feb 18, 2014 at 09:26 AM
ShowChatGUI() needs to be called from inside OnGUI so it is drawn on every frame. You can use a boolean setting to enable or disable the chat lobby.
Here is a example I experimented with
using UnityEngine;
using System.Collections;
public class lobby : MonoBehaviour {
public bool started;
public GUISkin gSkin;
public bool showChatLobby; //could as well be private, but like to see things like that in editor while developing
void OnGUI() {
if (!started) return;
GUI.skin = gSkin;
ShowChatGUI();
if(showChatLobby){
DrawLobbyGUI();
}
}
public void ShowChatGUI(){
if (GUI.Button (new Rect (10,Screen.height - 80,120,120), "Test Chat Button"))
{
if(!showChatLobby){
showChatLobby = true;
} else {
showChatLobby = false;
}
}
}
public void DrawLobbyGUI() {
GUI.Box(new Rect(10,10,150,25), "test text");
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
SmartFox SFSEvent.CONNECTION isn't calling 1 Answer
After collision how the run animation to die animation will change.. 0 Answers