//------------------------------------------------------------------
    /// Attempts to create a player and on success attempts to log that
    /// player into ChilliConnect.
    //------------------------------------------------------------------
    private void CreatePlayer()
    {
        Action <CreatePlayerRequest, CreatePlayerResponse> successCallback = (CreatePlayerRequest request, CreatePlayerResponse response) =>
        {
            m_chilliConnectId     = response.ChilliConnectId;
            m_chilliConnectSecret = response.ChilliConnectSecret;

            UnityEngine.Debug.Log("Player created with ChilliConnectId: " + m_chilliConnectId);

            ChangeAppState(AppStates.LOGIN);
        };

        Action <CreatePlayerRequest, CreatePlayerError> errorCallback = (CreatePlayerRequest request, CreatePlayerError error) =>
        {
            UnityEngine.Debug.Log("An error occurred while creating a new player: " + error.ErrorDescription);
        };

        var requestDesc = new CreatePlayerRequestDesc();

        requestDesc.DisplayName = "TestPlayer";

        var playerAccounts = m_chilliConnect.PlayerAccounts;

        playerAccounts.CreatePlayer(requestDesc, successCallback, errorCallback);
    }
示例#2
0
    void CreateAndLoginPlayer()
    {
        System.Action <CreatePlayerRequest, CreatePlayerResponse> successCallback = (CreatePlayerRequest request, CreatePlayerResponse response) =>
        {
            ChilliConnectId     = response.ChilliConnectId;
            ChilliConnectSecret = response.ChilliConnectSecret;

            //persist identifiers
            PlayerPrefs.SetString("ChilliConnectId", ChilliConnectId);
            PlayerPrefs.SetString("ChilliConnectSecret", ChilliConnectSecret);

            UnityEngine.Debug.Log("Player created with ChilliConnectId: " + ChilliConnectId + " ChilliSecret: " + ChilliConnectSecret);

            LoginPlayer();
        };

        System.Action <CreatePlayerRequest, CreatePlayerError> errorCallback = (CreatePlayerRequest request, CreatePlayerError error) =>
        {
            UnityEngine.Debug.Log("An error occurred while creating a new player: " + error.ErrorDescription);
        };

        var requestDesc = new CreatePlayerRequestDesc();

        chilliConnect.PlayerAccounts.CreatePlayer(requestDesc, successCallback, errorCallback);
    }
    // Start the ChilliConnect SDK, creating a player if one is not stored on the client.
    private void ChilliConnectInit()
    {
        // InitialiseChilliConnect SDK with our Game Token
        //chilliConnect = new ChilliConnectSdk("6PvaW0XKPZF3wUTOavDPwcLQUho9DQdS", true);
        chilliConnect = new ChilliConnectSdk("hxNSsyHz0KYmgNweytP4AiJGiuJIfl8t", true);

        // Create a Player and store the ChilliConnectId if we don't already have one
        if (!PlayerPrefs.HasKey("ChilliConnectId") || !PlayerPrefs.HasKey("ChilliConnectSecret"))
        {
            var createPlayerRequest = new CreatePlayerRequestDesc();

            // Create Player Account
            chilliConnect.PlayerAccounts.CreatePlayer(createPlayerRequest,
                                                      (CreatePlayerRequest request, CreatePlayerResponse response) =>
            {
                Debug.Log("Create Player successfull : " + response.ChilliConnectId);

                PlayerPrefs.SetString("ChilliConnectId", response.ChilliConnectId);
                PlayerPrefs.SetString("ChilliConnectSecret", response.ChilliConnectSecret);

                chilliConnectId     = response.ChilliConnectId;
                chilliConnectSecret = response.ChilliConnectSecret;
            },
                                                      (CreatePlayerRequest request, CreatePlayerError error) =>
            {
                Debug.Log("An error occurred Creating Player : " + error.ErrorDescription);
            }
                                                      );
        }
        else
        {
            chilliConnectId     = PlayerPrefs.GetString("ChilliConnectId");
            chilliConnectSecret = PlayerPrefs.GetString("ChilliConnectSecret");
        }
    }
示例#4
0
    /// Called when the ChilliConnect login call has failed. This could mean either
    /// a general error or that the FB player has no ChilliConnect account. In the latter
    /// case we link the current anonymous account to the current FB account.
    ///
    /// @param error
    ///         Error type and description
    ///
    private void OnChilliConnectFBLoginFailed(LogInUsingFacebookError error)
    {
        Debug.LogWarning("ChilliConnect logged in failed. Reason: " + error.ErrorDescription);

        //An edge case that is probably not even possible is that the player has never created a
        //ChilliConnect but has managed to login to FB. In this case we just create the account
        //now and link to that.
        if (IsChilliLoggedIn() == false)
        {
            var requestDesc = new CreatePlayerRequestDesc();
            m_chilliConnect.PlayerAccounts.CreatePlayer(requestDesc, (request, response) => OnChilliConnectAccountCreatedPostFB(response), (request, createError) => Debug.LogError(createError.ErrorDescription));
        }
        else if (error.ErrorCode == LogInUsingFacebookError.Error.LoginNotFound)
        {
            LinkFacebookAccountRequestDesc requestDesc = new LinkFacebookAccountRequestDesc(m_fbAccessToken);
            m_chilliConnect.PlayerAccounts.LinkFacebookAccount(requestDesc, (request, linkResponse) => OnChilliConnectLinked(linkResponse), (request, linkError) => Debug.LogError(linkError.ErrorDescription));
        }
    }
示例#5
0
    /// Initialised ChilliConnect, create and log in a player.
    ///
    private void Awake()
    {
        // Initialise ChilliConnect. Game token can be found on the game dashboard of ChilliConnect
        m_chilliConnect = new ChilliConnectSdk(GAME_TOKEN, true);

        // Create a new ChilliConnect player with the given display name if we don't have any credentials saved for the local player
        if (PlayerPrefs.HasKey("CCId") == true && PlayerPrefs.HasKey("CCSecret") == true)
        {
            Debug.Log("Player already exists. Logging in");
            m_chilliConnect.PlayerAccounts.LogInUsingChilliConnect(PlayerPrefs.GetString("CCId"), PlayerPrefs.GetString("CCSecret"), (loginRequest) => OnLoggedIn(), (loginRequest, error) => Debug.LogError(error.ErrorDescription));
        }
        else
        {
            Debug.Log("Creating Player");
            var requestDesc = new CreatePlayerRequestDesc();
            requestDesc.DisplayName = "TestyMcTestface";
            m_chilliConnect.PlayerAccounts.CreatePlayer(requestDesc, OnPlayerCreated, (AddEventRequest, error) => Debug.LogError(error.ErrorDescription));
        }
    }
示例#6
0
    /// Called when the FBInit call has completed
    /// either successfully or not. Determines if
    /// we have an existing FB/ChilliConnect login or not
    ///
    private void OnFBInitComplete()
    {
        if (FB.IsInitialized == true)
        {
            Debug.Log("FB initialised");

            FB.ActivateApp();

            //Check if we have an existing FB session and if so attempt to login to Chilli using it
            if (FB.IsLoggedIn == true)
            {
                Debug.Log("FB session already exists");

                //This is the access token required to login to ChilliConnect via FB.
                m_fbAccessToken = Facebook.Unity.AccessToken.CurrentAccessToken.TokenString;
                ChilliConnectFBLogin(m_fbAccessToken);
            }
            else
            {
                Debug.Log("No FB session already exists");

                //Check if we have a stored anonymous ChilliConnect token to login with
                if (PlayerPrefs.HasKey("CCId") == true && PlayerPrefs.HasKey("CCSecret") == true)
                {
                    Debug.Log("ChilliConnect account already exists. Logging in");
                    m_chilliConnect.PlayerAccounts.LogInUsingChilliConnect(PlayerPrefs.GetString("CCId"), PlayerPrefs.GetString("CCSecret"), (loginRequest) => OnChilliConnectAnonLoggedIn(), (loginRequest, error) => Debug.LogError(error.ErrorDescription));
                }
                else
                {
                    Debug.Log("No ChilliConnect account exists. Creating one");
                    //Create a new ChilliConnect account
                    var requestDesc = new CreatePlayerRequestDesc();
                    m_chilliConnect.PlayerAccounts.CreatePlayer(requestDesc, (request, response) => OnChilliConnectAccountCreated(response), (request, createError) => Debug.LogError(createError.ErrorDescription));
                }
            }
        }
        else
        {
            Debug.LogError("Failed to initialise FB SDK");
        }
    }
示例#7
0
    /// Creates a new ChilliConnect player account, replacing the currently
    /// persisted credentials. This effectivley logs out the existing player
    ///
    public void CreateNewAccount()
    {
        var requestDesc = new CreatePlayerRequestDesc();

        m_chilliConnect.PlayerAccounts.CreatePlayer(requestDesc, (request, response) => OnChilliConnectAccountCreated(response), (request, createError) => Debug.LogError(createError.ErrorDescription));
    }