-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Usef Farahmand edited this page Sep 11, 2024
·
3 revisions
Welcome to the UAPI Wiki! This documentation will guide you through the features, installation, and usage of the UAPI library.
UAPI depends on UniTask, which needs to be installed before adding UAPI. Follow these steps:
- Open Unity and go to Window -> Package Manager.
- Press the
+button and select Add package from git URL... - Enter the following URL and press Add:
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask
Option 1: Install via Git URL
- After installing
UniTask, open Window -> Package Manager in Unity. - Press the
+button and choose Add package from git URL... - Enter the following URL to install UAPI:
https://github.com/UModules/UAPI.gitupm
Option 2: Install via Manifest File
Alternatively, you can install UAPI by editing your manifest.json file located in the Packages folder of your Unity project.
Add the following line to your dependencies:
"com.umodules.uapi": "https://github.com/UModules/UAPI.git#upm"
Option 3: Manual Installation
- Clone the UAPI repo or download the latest release from GitHub.
- Add the UAPI folder to your Unity project manually or import the .unitypackage file.
- Easy Integration: Simplifies the integration of APIs into your applications.
- Comprehensive Documentation: Detailed documentation to help you get started quickly.
- Modular Architecture: Highly modular design allows for easy customization and extension.
- Robust Testing: Includes a suite of tests to ensure reliability and stability.
- In Unity, go to Assets -> Create -> UAPIModule -> APIConfig to create a new
APIConfigScriptable Object. - Fill in the variables within the
APIConfigasset in the Inspector, which include:- Base URL Configuration: The base URL for the API.
- Endpoint: The specific endpoint of the API.
- Method Type: The HTTP method (GET, POST, etc.).
- Headers: Optional headers for the API request.
- Needs Auth Header: Whether authorization is required.
- Timeout: The timeout duration (in milliseconds).
- Use Bearer Prefix: Whether to use the 'Bearer' prefix in the authorization header.
- Create a new Unity scene:
- In Unity, go to File -> New Scene and save the scene with a relevant name (e.g., "APITestScene").
- Create an empty GameObject:
- Right-click in the Hierarchy window and select Create Empty to create an empty GameObject.
- Name it something like "API Test Object."
- Create the
APITestscript:- With the new GameObject selected, go to the Inspector window.
- Click Add Component and search for
APITest. Attach this script to the empty GameObject.
- Serialize the APIConfig object:
- In the Inspector of the GameObject with the
APITestscript, you’ll see a field for theAPIConfigobject. - Drag and drop the
APIConfigasset you created earlier into this field to serialize it.
- In the Inspector of the GameObject with the
- Save the scene if you haven’t already.
- Press Play in Unity to run the project.
- The
APITestscript will automatically execute and send a request based on the serializedAPIConfig. You can monitor the console for any debug messages such as the API response or error messages.
using UAPIModule.Assets;
using UAPIModule.SharedTypes;
using UAPIModule.Tools;
using UnityEngine;
namespace UAPIModule.Tests
{
public class APITest : MonoBehaviour
{
private const string API_KEY = "TEST";
public APIConfig apiConfig;
private void Awake()
{
APIClient.CreateRequest(API_KEY, NetworkLoadingHandlerCreator.CreateAndGet());
}
private async void Start()
{
RequestFeedbackConfig feedbackConfig = RequestFeedbackConfig.InitializationFeedback;
NetworkResponse response = await APIClient.SendRequest(API_KEY, apiConfig.Get(), feedbackConfig, null);
if (response.isSuccessful)
{
Debug.Log(response.ToString());
}
else
{
Debug.LogError($"Request failed: {response.errorMessage}");
}
}
}
}This project is licensed under the MIT License. See the LICENSE file for details.