# Game Connect

GameConnect gives your users advantages of using playing the game as long as they are logged in the system. The difference with [email-and-password-login](https://docs.reneverse.io/publisher-flow/player-authentication/email-and-password-login "mention") is that the user should admitting the logging in attempt on the Reneverse website:

<figure><img src="https://2133953908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2R0efebFfiw8qumiNT9v%2Fuploads%2FtvNOGv5VJ4kdXFXwsOM7%2FGroup%2042.png?alt=media&#x26;token=68cf2477-3a2d-41c3-9a9f-1eb2df4ecc97" alt=""><figcaption><p>Once GameConnect happens, the user should confirm it on the website </p></figcaption></figure>

The `ReneAPIManager` class is a utility class that manages connections and interactions with the ReneVerse API. It provides several static methods to initialize the API, handle user authentication, connect to games, and perform various other operations.

#### Methods: GameConnect and GameConnectWithUserName

**Method: `GameConnect`**

**Signature**:

```csharp
public static async Task<bool> GameConnect(string email)
```

**Description**: The `GameConnect` method connects to the ReneVerse game using the provided email. This connection requires user authorization on the ReneVerse website.

**Parameters**:

* `email` (string): The email address of the user. This email must be registered on the ReneVerse website.

**Returns**:

* `Task<bool>`: A task representing the asynchronous operation. The task result is a boolean indicating whether the connection was successful.

**Method: `GameConnectWithUserName`**

**Signature**:

```csharp
public static async Task<bool> GameConnectWithUserName(string userName)
```

**Description**: The `GameConnectWithUserName` method connects to the ReneVerse game using the provided username. This connection also requires user authorization on the ReneVerse website.

**Parameters**:

* `userName` (string): The username of the user. This username must be registered on the ReneVerse website.

**Returns**:

* `Task<bool>`: A task representing the asynchronous operation. The task result is a boolean indicating whether the connection was successful.

#### Usage

The `GameConnect` and `GameConnectWithUserName` methods can be called from any script within the Unity project. Typically, they would be called when the user attempts to connect to the game through the game's user interface.

**Example Usage in Unity**

Here's an example of how to use the `GameConnect` and `GameConnectWithUserName` methods within a Unity script. This example assumes you have a basic UI setup with input fields for the email or username and a button to trigger the connection process.

1. **Create a Connection UI**:
   * Add Input Fields for email or username.
   * Add a Button for the connection action.
2. **Attach a Script to the Button**:

   ```csharp
   csharpCopy codeusing UnityEngine;
   using UnityEngine.UI;
   using ReneVerse;

   public class ConnectionManager : MonoBehaviour
   {
       public InputField emailInputField;
       public InputField userNameInputField;
       public Text statusText;

       public async void OnConnectButtonClicked()
       {
           string email = emailInputField.text;
           string userName = userNameInputField.text;
           
           bool connectionSuccessful;
           if (!string.IsNullOrEmpty(email))
           {
               connectionSuccessful = await ReneAPIManager.GameConnect(email);
           }
           else
           {
               connectionSuccessful = await ReneAPIManager.GameConnectWithUserName(userName);
           }

           if (connectionSuccessful)
           {
               statusText.text = "Connection successful! Please authorize on the ReneVerse website.";
               // Proceed to the next scene or game state
               // Now players have the benefits of logging in
           }
           else
           {
               statusText.text = "Connection failed. Please check your credentials or registration status.";
           }
       }
   }
   ```
3. **Initialize the ReneVerse API**: Ensure that the API is initialized before calling the connection methods. This can be done in the `Start` method of a Unity script or any other appropriate place in your game.

   ```csharp
   csharpCopy codevoid Start()
   {
       ReneAPIManager.InitializeAPI();
   }
   ```

#### Detailed Explanation

**Initialization**

Before calling the `GameConnect or GameConnectWithUserName`method, it is crucial to initialize the ReneVerse API. The `InitializeAPI` method sets up the API using the credentials stored in the `ReneAPICreds` in the Reneverse Window that Rene Sdk Provides (Shift + R/ Window -> Reneverse Settings).

**Handling Game Connection**

The `GameConnect` and `GameConnectWithUserName` methods utilize the `GameAPI` class to send a connection request to the ReneVerse backend. Upon sending the request, users need to authorize the connection on the ReneVerse website.

```csharp
public static async Task<bool> GameConnect(string email)
{
    GameAPI gameAPI = api.Game();
    return await gameAPI.Connect(email);
}

public static async Task<bool> GameConnectWithUserName(string userName)
{
    GameAPI gameAPI = api.Game();
    return await gameAPI.ConnectWithUserName(userName);
}
```

**Customization**

Developers can customize the connection implementation as needed. For instance, input parameters can be gathered through different UI elements, such as text fields or dropdowns. The process of integrating the connection functionality into the game's flow is flexible and can be adapted to fit various design requirements.

#### Summary

The `ReneAPIManager.GameConnect` and `ReneAPIManager.GameConnectWithUserName` methods provide a straightforward way to connect to the ReneVerse game environment in Unity games. These methods require user authorization through the ReneVerse website, ensuring secure connections. By following the steps outlined above, developers can easily integrate connection functionality into their games, allowing users to connect using their registered email or username. The methods are asynchronous and return a boolean indicating the success of the connection attempt, enabling developers to handle successful and failed connections appropriately within their game.
