Search code examples
unity-game-engineunityscriptphoton

photon chat unity plugin - how to know if a friend is online or not


I am using photon chat plugin in a unity3d multiplayer game. I have added some friends and can send them private message. I want to show if that friend is online or not.

I can use on status update callback, but it will show only friends who changed status. How can I get friends who are already online?

I have gone through syntax of FriendInfo, but can not figure out how to use it. Any small example of knowing some specific client is online or not will be really helpful.

Thank you!


Solution

  • To get friends status updates you send a string array with their usernames to Photon.

    friends = new List<string>() { "Ford", "Zaphod", "Marvin", "Eddie" };
    chatClient.AddFriends(friends.ToArray());
    

    For all friends online you'll receive an initial update with the current status for each to OnStatusUpdate() on your IChatClientListener interface.

    OnStatusUpdate( string user, int status, bool gotMessage, object message )
    {
        Console.WriteLine( "Status change for: " + user + " to: " + status );
    }
    

    Friends no status update is received for are offline.