# Player Authentication

### `ReneAPICreds`

The `ReneAPICreds` class stores your ReneVerse API credentials.

#### Fields

The following fields are available in the `ReneAPICreds` class:

* `APIKey` - Your ReneVerse API Key.
* `PrivateKey` - Your ReneVerse Private Key.
* `GameID` - Your ReneVerse Game ID.
* `HostName` - Your ReneVerse Host Name.

### `ReneAPIManager`

The `ReneAPIManager` class is used to initialize the ReneVerse API and connect to the ReneVerse game.

#### `Init()`

The `Init()` method initializes the ReneVerse API.

```
var reneApi = ReneAPIManager.Init();
```

#### `GameConnect()`

`ReneAPIManager.GameConnect(emailInputField.text, _onGraphQlHttpRequestException)` connects the user to the game by making an asynchronous call to the `GameConnect` method of the `ReneAPIManager` class. This method takes in the email (should be registered on the ReneVerse service) input field text and an optional callback function to handle GraphQL HTTP request exceptions. The boolean value `connectedGame` is returned if the connection is successful.

```
bool connectedGame = await ReneAPIManager.GameConnect(emailInputField.text, _onGraphQlHttpRequestException);

if (!connectedGame) return;
```

### **`reneApi.IsAuthorized()`**

\
`reneApi.IsAuthorized()` is a method of the `API` class that returns a boolean value indicating if the user is authorized to access the API.

### Connect() example method

Summing up everything mentioned above the following method could be created to connect to our services to use the assets in your awesome games

```
public async void Connect() { 
// Check if email input field is not empty 
if (emailInputField.text == "") return;
// Initialize reneApi instance
var reneApi = ReneAPIManager.Init();

// Connect to the game
bool connectedGame = await ReneAPIManager.GameConnect(emailInputField.text, _onGraphQlHttpRequestException);

// Check if the game is connected successfully
if (!connectedGame) return;

// Check if reneApi instance is authorized
if (reneApi.IsAuthorized())
{
    // Update UI and retrieve user assets
    _connecting = false;
    PlayButton.interactable = true;
    AssetsResponse.AssetsData userAssets = await reneApi.Game().Assets();
    SelectCharacterPanel.SetActive(true);
    // ...
}
```

}

### Extensions

The `Extensions` class contains some handy extension methods you can use in your Unity project.

#### `SeparateCamelCase()`

The `SeparateCamelCase()` method separates camel case strings.

#### `UnderscoresToSpaces()`

The `UnderscoresToSpaces()` method replaces underscores with spaces.

#### `ToLoginUrl()`

The `ToLoginUrl()` method creates a login URL.

#### `AddEnterYour()`

The `AddEnterYour()` method adds "Enter your" to a string.

#### `GetName()`

The `GetName()` method gets the name of a member.

### Conclusion

Congratulations! You have successfully learned how to use the ReneVerse Unity SDK to integrate NFTs into your Unity games. Now it's time to start building amazing games with the power of the blockchain! Happy coding!

### `ReneAPICreds`

The `ReneAPICreds` class stores your ReneVerse API credentials.

#### Fields

The following fields are available in the `ReneAPICreds` class:

* `APIKey` - Your ReneVerse API Key.
* `PrivateKey` - Your ReneVerse Private Key.
* `GameID` - Your ReneVerse Game ID.

### `ReneAPIManager`

The `ReneAPIManager` class is used to initialize the ReneVerse API and connect to the ReneVerse game.

#### `API()`

The `API()` method returns the ReneVerse API client.

```
var reneApi = ReneAPIManager.API();
```

#### `GameConnect()`

```
var connected = await reneApi.Game().Connect(emailInputField.text, _onGraphQlHttpRequestException);
```

connects the user to the game by making an asynchronous call to the GameConnect method of the ReneAPIManager class. This method takes in the email (should be registered on the ReneVerse service) input field text and an optional callback function to handle GraphQL HTTP request exceptions. The boolean value connectedGame is returned if the connection is successful.

## `Getting the Assets`

Afterwards you have many ways to implement loaded from ReneVerse service information about users' Assets and here is one of them. We can use Coroutines since they are Unity specific and less error prone:

```
StartCoroutine(ConnectReneService(reneApi));
```

&#x20;As you remember we are waiting for the user to accept his entry into the ReneVerse system and to get an access to their assets. In order to achieve this you could do the following \ <br>

```
private IEnumerator ConnectReneService(API reneApi)
{
    var counter = 0;
    var userConnected = false;
    //Interval how often the code checks that user accepted to log in
    var secondsToIncrement = 1;
    while (counter <= secondsToWait && !userConnected)
    {
        print(counter);
        if (reneApi.IsAuthorized())
        {
        
        
        //Here can be added any extra logic once the user logged in
        
        
        
            yield return GetUserAssetsAsync(reneApi);
            userConnected = true;
        }

        yield return new WaitForSeconds(secondsToIncrement);
        counter += secondsToIncrement;
    }
}
```

Now let's look at the GetUserAssetsAsync(reneApi) method that has the necessary information in it&#x20;

```
private async Task GetUserAssetsAsync(API reneApi)
{
    AssetsResponse.AssetsData userAssets = await reneApi.Game().Assets();
    //By this way you could check in the Unity console your NFT assets
    userAssets?.Items.ForEach
    (asset => Debug.Log
        ($" - Asset Id '{asset.NftId}' Name '{asset.Metadata.Name}"));
    userAssets?.Items.ForEach(asset =>
    {
        string assetName = asset.Metadata.Name;
        string assetImageUrl = asset.Metadata.Image;
        string assetStyle = "";
        asset.Metadata?.Attributes?.ForEach(attribute =>
        {
        //Keep in mind that this TraitType should be preset in your Reneverse Account
            if (attribute.TraitType == "Style")
            {
                assetStyle = attribute.Value;
            }
        });
        //An example of how you could keep retrieved information
        Asset assetObj = new Asset(assetName, assetImageUrl, assetStyle);
        //one of many ways to add it to the game logic 
        _assetManager.userAssets.Add(assetObj);
    });
}
```

Here is mine and indeed the name of the Attribute is "Style"

<figure><img src="https://2133953908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2R0efebFfiw8qumiNT9v%2Fuploads%2FNCa52Jua1y6YeVDLSuju%2Fimage.png?alt=media&#x26;token=70f974c0-794b-4d1f-826c-3df1587dc575" alt=""><figcaption></figcaption></figure>

You set this values once you create assets and can modify them in this menu

<figure><img src="https://2133953908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2R0efebFfiw8qumiNT9v%2Fuploads%2FmN5vIrLHCRynJDmIXzJo%2Fimage.png?alt=media&#x26;token=dceec84e-8126-405c-8da4-e13e39806c1e" alt=""><figcaption></figcaption></figure>

## `An example of Asset entity`

Here is how Asset class is set up in our case but it is up to you how you hook up the retrieved information within your game.&#x20;

```
public class Asset
{
    public string AssetName { get; set; }
    public string AssetUrl { get; set; }

    public string AssetStyle {get; set;}
    public Asset(string assetName, string assetUrl, string assetStyle)
    {
        AssetName = assetName;
        AssetUrl = assetUrl;
        AssetStyle = assetStyle;
    }
}
```

#### Congratulations! You have successfully learned how to use the ReneVerse Unity SDK to integrate NFTs into your Unity games. Now it's time to start building amazing games with the power of the blockchain! Happy coding!
