Chat viking suddently stopped working ?
Options
Hello,
As the title says, the ChatVik.cs suddently stopped working : I can see the text field and I can write in it, but when I press enter, it does not send the message (and the message is still shown on the textfield).
It's from the viking demo, I have no idea why it stopped working (it worked great before).
here is the script :
As the title says, the ChatVik.cs suddently stopped working : I can see the text field and I can write in it, but when I press enter, it does not send the message (and the message is still shown on the textfield).
It's from the viking demo, I have no idea why it stopped working (it worked great before).
here is the script :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// This simple chat example showcases the use of RPC targets and targetting certain players via RPCs.
/// </summary>
public class ChatVik : Photon.MonoBehaviour
{
public static ChatVik SP;
public List<string> messages = new List<string>();
private int chatHeight = (int)140;
private Vector2 scrollPos = Vector2.zero;
private string chatInput = "";
private float lastUnfocusTime = 0;
void Awake()
{
SP = this;
}
void OnGUI()
{
GUI.SetNextControlName("");
GUILayout.BeginArea(new Rect(0, Screen.height - chatHeight, Screen.width, chatHeight));
//Show scroll list of chat messages
scrollPos = GUILayout.BeginScrollView(scrollPos);
GUI.color = Color.red;
for (int i = messages.Count - 1; i >= 0; i--)
{
GUILayout.Label(messages);
}
GUILayout.EndScrollView();
GUI.color = Color.white;
//Chat input
GUILayout.BeginHorizontal();
GUI.SetNextControlName("ChatField");
chatInput = GUILayout.TextField(chatInput, GUILayout.MinWidth(200));
if (Event.current.type == EventType.keyDown && Event.current.character == '\n'){
if (GUI.GetNameOfFocusedControl() == "ChatField")
{
SendChat(PhotonTargets.All);
lastUnfocusTime = Time.time;
GUI.FocusControl("");
GUI.UnfocusWindow();
}
else
{
if (lastUnfocusTime < Time.time - 0.1f)
{
GUI.FocusControl("ChatField");
}
}
}
//if (GUILayout.Button("SEND", GUILayout.Height(17)))
// SendChat(PhotonTargets.All);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
public static void AddMessage(string text)
{
SP.messages.Add(text);
if (SP.messages.Count > 15)
SP.messages.RemoveAt(0);
}
void SendChat(PhotonTargets target)
{
if (chatInput != "")
{
photonView.RPC("SendChatMessage", target, chatInput);
chatInput = "";
}
}
void SendChat(PhotonPlayer target)
{
if (chatInput != "")
{
chatInput = "[PM] " + chatInput;
photonView.RPC("SendChatMessage", target, chatInput);
chatInput = "";
}
}
[RPC]
void SendChatMessage(string text, PhotonMessageInfo info)
{
AddMessage("[" + info.sender + "] " + text);
}
void OnLeftRoom()
{
this.enabled = false;
}
void OnJoinedRoom()
{
this.enabled = true;
}
void OnCreatedRoom()
{
this.enabled = true;
}
}
0
Comments
-
It works in the most recently updated Viking Demo from the Asset Store.
Download that and compare the code. Use some diff tool, to make that easier.0