Help please with Photon Chat!

Options
mauri86
edited September 2014 in Photon Chat
Hi! and sorry for making this noob question, Im more an artist than a developer, and I am having real issues
setting the chat system onto my game.

I have the example Photon chat for unity but I cannot identify the exact line of code that writes the message
of the input to the label of the chat room to everyone, can someone help me?

this is what I got until no:
using System;
using System.Collections.Generic;
using ExitGames.Client.Photon.Chat;
using UnityEngine;

public class Chat : MonoBehaviour, IChatClientListener
{
	public string ChatAppId; 
	public ChatClient chatClient;

	private ChatChannel selectedChannel;
	public string[] channelsToJoin;
	private string selectedChannelName; 

	private string chat = "";
	private string inputLine = "";

	private Rect GUIRect = (new Rect(0,0,Screen.width/2,Screen.height/2));

	// Use this for initialization
	public void Start () 
	{
		Application.runInBackground = true;

		chatClient = new ChatClient(this);
		chatClient.Connect(ChatAppId, "1.0", "Mauri", null);

		chatClient.Subscribe(channelsToJoin);
	}
	
	public void Update()
	{
		if (this.chatClient != null)
		{
			this.chatClient.Service();  // make sure to call this regularly! it limits effort internally, so calling often is ok!
		}
	}

	void OnGUI()
	{
		GUILayout.BeginArea(GUIRect);
		GUILayout.FlexibleSpace();
		GUILayout.Label(chat);
		inputLine = GUILayout.TextField(inputLine);
		GUILayout.EndArea();

		if (this.chatClient.State != ChatState.ConnectedToFrontEnd)
		{
			chat = "Connecting...";
		}
	}

	public void OnApplicationQuit()
	{
		if (this.chatClient != null)
		{
			this.chatClient.Disconnect();
		}
	}

	public void OnConnected()
	{
		chat = "Online";
	}
	
	public void OnDisconnected()
	{
		chat = "You got disconnected from chat...";
	}
	
	public void OnChatStateChange(ChatState state)
	{
		// use OnConnected() and OnDisconnected()
		// this method might become more useful in the future, when more complex states are being used.
	}
	
	public void OnSubscribed(string[] channels, bool[] results)
	{
		chatClient.PublishMessage("General", "hi");
	}
	
	public void OnUnsubscribed(string[] channels)
	{
	}
	
	public void OnGetMessages(string channelName, string[] senders, object[] messages)
	{
	}
	
	public void OnPrivateMessage(string sender, object message, string channelName)
	{
		// as the ChatClient is buffering the messages for you, this GUI doesn't need to do anything here
		// you also get messages that you sent yourself. in that case, the channelName is determinded by the target of your msg
	}
	
	public void OnStatusUpdate(string user, int status, bool gotMessage, object message)
	{
	}
}

Comments

  • Tobias
    Options
    The ChatClient has a list of channels. Per channel, it can get the messages.
    The demo should be using this, so I am not copying code here. Please have another look.