Friday, June 17, 2011

Foray into Photon - Part 8 - IGameListener

So we have our interface defining our GameStates but I said we are missing something. Exit Games created another interface called the IGameListener. It's job is to listen to events from the game and update the player based on those events.


using System;
using ExitGames.Client.Photon;


public interface IGameListener
{
    bool IsDebugLogEnabled { get; }


    void LogDebug(Game game, string message);


    void LogError(Game game, string message);


    void LogError(Game game, Exception exception);


    void LogInfo(Game game, string message);


    void OnConnect(Game game);


    void OnDisconnect(Game game, StatusCode returnCode);


}

We can then add this interface to our Login.cs as an interface and inherit these functions. These are how they look in Login.cs

    #region Inherited Interfaces

    #region IGameListener
    public bool IsDebugLogEnabled
    {
        get { return true; }
    }

    public void LogDebug(Game game, string message)
    {
        Debug.Log(message);
    }

    public void LogError(Game game, string message)
    {
        Debug.Log(message);
    }

    public void LogError(Game game, Exception exception)
    {
        Debug.Log(exception.ToString());
    }

    public void LogInfo(Game game, string message)
    {
        Debug.Log(message);
    }

    public void OnConnect(Game game)
    {
        Debug.Log("connected");
    }

    public void OnDisconnect(Game game, StatusCode returnCode)
    {
        Debug.Log("disconnected");
    }

    #endregion

    #endregion

This allows us to log any errors that occur during the course of our program running. Next time we will connect our game state and listener into our game. Stay Tuned

No comments: