/// <summary>
    /// Function used to initialize facebook.
    /// </summary>
    public void Initialize(ProjectDelegates.FacebookLoginCallback OnLoginCompletedCallback)
    {
        this.OnFacebookLoginCompletedCallback = OnLoginCompletedCallback;

        if (!FB.IsLoggedIn)
        {
            FB.Init(OnInitCompleted, OnHideUnity);
        }
        else
        {
            //this.OnFacebookLoginCompletedCallback(FB.AccessToken);
            FB.API("me", Facebook.HttpMethod.GET, OnProfileInfoLoaded);
        }
    }
    /// <summary>
    /// Method to be called when the user wants to create a new room.
    /// </summary>
    public void CreateNewRoom(int numberOfPlayers,ProjectDelegates.RoomInfoCallback RoomCreatedCallback, int level)
    {
        OnJoinedRoomCallback = RoomCreatedCallback;

        ExitGames.Client.Photon.Hashtable customParams = new ExitGames.Client.Photon.Hashtable();
        customParams.Add("C0", level);

        RoomOptions options = new RoomOptions();
        options.maxPlayers = numberOfPlayers;

        TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default);

		//PhotonNetwork.CreateRoom ("",options,typedLobby);
		//PhotonNetwork.CreateRoom ("", true, true, numberOfPlayers);
		// testing this to git rid of the build warning
		PhotonNetwork.CreateRoom("", options, typedLobby);
		
    }
    /// <summary>
    /// Method to be called when the user wants to try to connect to an existing room.
    /// </summary>
    public void JoinRoom(byte maxPlayers, int level, ProjectDelegates.RoomInfoCallback JoinedRoomCallback)
    {
        this.maxPlayers = maxPlayers;
        this.level = level;
        OnJoinedRoomCallback = JoinedRoomCallback;

        string sqlFilter = "C0 > " + (level-3) + " AND C0 < " + (level+3);

		Debug.Log (sqlFilter);

        TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default);


        PhotonNetwork.JoinRandomRoom(null,maxPlayers,MatchmakingMode.FillRoom,typedLobby,"");
		//PhotonNetwork.JoinRandomRoom (, MatchmakingMode.FillRoom, typedLobby, sqlFilter);
    }
 /// <summary>
 /// Updates Callback to handle start game.
 /// </summary>
 /// <param name="OnStartGame">Callback.</param>
 public void SetOnStartGame(ProjectDelegates.SimpleCallback OnStartGame)
 {
     this.OnStartGame = OnStartGame;
 }
 /// <summary>
 /// Updates callback to handle timer stop.
 /// </summary>
 /// <param name="OnTimerStop">Callback.</param>
 public void SetOnTimerStop(ProjectDelegates.SimpleCallback OnTimerStop)
 {
     this.OnTimerStop = OnTimerStop;
 }
    /// <summary>
    /// Function used to login an existing player with PlayFab.
    /// </summary>
    /// <param name="username">User's username</param>
    /// <param name="password">User's password</param>
    /// <param name="OnLoginCompletedCallback">Function to call after process ends</param>
    public void LoginWithPlayFab(string username, string password, ProjectDelegates.PlayFabLoginCallback OnLoginCompletedCallback)
    {
        this.OnLoginCompletedCallback = OnLoginCompletedCallback;

        PlayFabSettings.TitleId = playFabGameID;



        LoginWithPlayFabRequest request = new LoginWithPlayFabRequest();
        request.Username = username;
        request.Password = password;
        request.TitleId = playFabGameID;

        PlayFabClientAPI.LoginWithPlayFab(request, OnLoginCompleted, OnLoginError);
    }
 /// <summary>
 /// Updates Callback to handle timer start.
 /// </summary>
 /// <param name="OnTimerStarted">Callback.</param>
 public void SetOnTimerStarted(ProjectDelegates.SimpleCallback OnTimerStarted)
 {
     this.OnTimerStarted = OnTimerStarted;
 }
 /// <summary>
 /// Sets the callback list that handles stats upgrades.
 /// </summary>
 /// <param name="statsCallbacks">Callbacks list, ordered by enum HashCode</param>
 public void SetUpgradesCallbacks(ProjectDelegates.OnPlayerBoughtStatUpgradeCallback[] statsCallbacks)
 {
     this.OnStatsUpgradesCallback = statsCallbacks;
 }
    /// <summary>
    /// Method used to initialize and connect to Photon servers.
    /// </summary>
    public void Initialize(ProjectDelegates.RoomsListCallback ConnectedCallback)
    {
        playersInRoom = new List<PhotonPlayer>();
        OnPhotonConnected = ConnectedCallback;

        if (!PhotonNetwork.connected)
        {


            PhotonNetwork.autoJoinLobby = true;
            PhotonNetwork.ConnectUsingSettings("4.5");
            PhotonNetwork.playerName = AccountManager.instance.displayName;
        }
        else
        {
            ConnectedCallback(PhotonNetwork.GetRoomList());
        }
    }
    /// <summary>
    /// Gets all catalog items.
    /// </summary>
    /// <param name="OnCatalogLoaded">Callback when completes.</param>
    public void GetAllCatalogItems(ProjectDelegates.PlayFabCatalogListCallback OnCatalogLoaded)
    {
        this.OnCatalogLoadedCallback = OnCatalogLoaded;

        if (catalogItems == null)
        {
            GetCatalogItemsRequest request = new GetCatalogItemsRequest();
            request.CatalogVersion = "Test";
            PlayFabClientAPI.GetCatalogItems(request, OnCatalogItemsLoaded, OnCatalogItemsError);
        }
        else
        {
            OnCatalogLoadedCallback(catalogItems);
        }
    }
    /// <summary>
    /// Tries to buy item with virtual currency.
    /// </summary>
    /// <param name="item">Item to buy.</param>
    /// <param name="OnBuySuccess">Callback in case scceeds.</param>
    public void BuyItemWithVirtualCurrency(CatalogItem item,ProjectDelegates.PlayFabItemBuyCallback OnBuySuccess)
    {
        this.OnBuySuccessCallback = OnBuySuccess;

        PurchaseItemRequest request = new PurchaseItemRequest();
        request.ItemId = item.ItemId;
        request.Price = (int)item.VirtualCurrencyPrices["1"];
        request.VirtualCurrency = "1";

        PlayFabClientAPI.PurchaseItem(request, OnPurchaseSuccess, OnPurchaseError);
    }
    /// <summary>
    /// Method used to get a defined number of users starting from a defined position, based on a defined stat.
    /// </summary>
    /// /// <param name="property">Property to define the leaderboard.</param>
    /// <param name="maxResults">Maximum number of players to return.</param>
    /// /// <param name="startPosition">Position to start getting the leaderboard.</param>
    /// <param name="OnLeaberboardLoaded">Callback when the leaderboard is loaded.</param>
    public void GetLeaderboardFromPosition(string property, int maxResults, int startPosition, ProjectDelegates.PlayFabLeaderboardCallback OnLeaberboardLoaded)
    {
        OnLeaderboardLoadedCallback = OnLeaberboardLoaded;

        GetLeaderboardRequest request = new GetLeaderboardRequest();
        request.StatisticName = property;
        request.MaxResultsCount = maxResults;
        request.StartPosition = startPosition;

        PlayFabClientAPI.GetLeaderboard(request, OnGetLeaderboardFromPositionResult, OnGetLeaderboardError);
    }
    /// <summary>
    /// Method used to get a defined number of users around the current user, based on a defined stat.
    /// </summary>
    /// <param name="property">Property to define the leaderboard.</param>
    /// <param name="maxResults">Maximum number of players to return.</param>
    /// <param name="OnLeaberboardLoaded">Callback when the leaderboard is loaded.</param>
    public void GetLeaderboardAroundMe(string property, int maxResults, ProjectDelegates.PlayFabLeaderboardCallback OnLeaberboardLoaded)
    {
        OnLeaderboardLoadedCallback = OnLeaberboardLoaded;

        GetLeaderboardAroundCurrentUserRequest request = new GetLeaderboardAroundCurrentUserRequest();
        request.StatisticName = property;
        request.MaxResultsCount = maxResults;

        PlayFabClientAPI.GetLeaderboardAroundCurrentUser(request, OnGetLeaderboardAroundMeResult, OnGetLeaderboardError);
    }
    /// <summary>
    /// Function to be called to link Facebook user with PlayFab user 
    /// (creates a new one if not exists, logins existing user if exists).
    /// </summary>
    /// <param name="facebookAccessToken">Facebook's access token</param>
    /// <param name="OnLoginCompletedCallback">Function to call after process ends</param>
    public void LoginWithFacebook(string facebookAccessToken, string facebookName, string facebookPictureURL, ProjectDelegates.PlayFabLoginCallback OnLoginCompletedCallback)
    {
        this.OnLoginCompletedCallback = OnLoginCompletedCallback;

        this.playerDisplayName = facebookName;
        this.playerPictureURL = facebookPictureURL;

        PlayFabSettings.TitleId = playFabGameID;

        LoginWithFacebookRequest facebookRequest = new LoginWithFacebookRequest();
        facebookRequest.CreateAccount = true;
        facebookRequest.TitleId = playFabGameID;
        facebookRequest.AccessToken = facebookAccessToken;

        PlayFabClientAPI.LoginWithFacebook(facebookRequest, OnLoginCompleted, OnLoginError);
    }
 /// <summary>
 /// Adds callback listeners. Used to handle actual player input, and give it to the movement manager, or somewhere else needed.
 /// </summary>
 /// <param name="startCallback">Touch start callback.</param>
 /// <param name="moveCallback">Touch moved callback.</param>
 /// <param name="endCallback">Touch ended callback.</param>
 public void AddListener(ProjectDelegates.TouchStartCallback startCallback, ProjectDelegates.TouchMoveCallback moveCallback, ProjectDelegates.TouchEndCallback endCallback)
 {
     this.OnTouchStart += startCallback;
     this.OnTouchMove += moveCallback;
     this.OnTouchEnd += endCallback;
 }
 /// <summary>
 /// Updates Callback to handle room properties change.
 /// </summary>
 /// <param name="OnPlayersUpdate">Callback.</param>
 public void SetPropertiesChangeCallback(ProjectDelegates.RoomInfoCallback OnPlayersUpdate)
 {
     OnRoomPropertiesUpdate = OnPlayersUpdate;
 }
 /// <summary>
 /// Starts facebook login.
 /// </summary>
 /// <param name="OnLoginCompleted">Login completed callback.</param>
 public void LoginWithFacebook(ProjectDelegates.SimpleCallback OnLoginCompleted)
 {
     this.OnLoginCompleted = OnLoginCompleted;
     facebookManager.Initialize(OnFacebookLoginCompleted);
     //this.OnFacebookLoginCompleted("CAAKVX8jV8zcBACCXCuUF8zsOCZApmCKnqtbpubD0cPIYoasjgtizxF6DmAgDkZBxCpPnfZCgyAPpGob2OkdinoOZCPy35nm1AJ3F3gET9kwS9850iKkwzNhZCARvytWYLTQfvl1Uqe02ANJVy5tPT2jlCmrmXCfi0nW2wWM18aPy58T4TmPkTPXUhJhOgrBUY9xW2e88lNW9Vs3aSBWEewru83KlhkYUZD", "Igor Pereira");
 }
    /// <summary>
    /// Function to be called when the user will create a new account from scratch.
    /// </summary>
    /// <param name="username">User's chosen username</param>
    /// <param name="password">User's chosen password</param>
    /// <param name="email">User's  chosen email</param>
    /// <param name="OnUserCreatedCallback">Function to call after process ends.</param>
    public void CreateNewUser(string username, string password, string email, ProjectDelegates.PlayFabLoginCallback OnUserCreatedCallback)
    {
        this.OnLoginCompletedCallback = OnUserCreatedCallback;

        PlayFabSettings.TitleId = playFabGameID;

        RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
        request.Username = username;
        request.Password = password;
        request.Email = email;
        request.TitleId = playFabGameID;

        PlayFabClientAPI.RegisterPlayFabUser(request, OnRegistrationCompleted, OnLoginError);
    }