Skip to content

Commit 600d945

Browse files
committed
docs: add Unity scripts section with usage instructions
1 parent 4e267f6 commit 600d945

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ API_KEY=your-admin-key
9191

9292
Only the endpoint `/api/testers/validate-access` is publicly accessible for validating tester access, and `/api/testers/{accessKey}/playtime` is publicly accessible for reporting accumulated playtime.
9393

94+
## 📘 HTTP Request Examples
95+
96+
You can use this [Playtesters.API.http](https://github.com/DevD4v3/Playtesters.API/blob/master/src/Playtesters.API.http) file (VS Code / Rider / Visual Studio compatible) to test every endpoint of the API.
97+
9498
## 🎮Unity Integration
9599

96100
- The `/api/testers/validate-access` endpoint should be called before allowing gameplay or enabling private build features to ensure the tester has valid access.
@@ -102,9 +106,28 @@ Below is a quick demonstration of how you can integrate the Playtesters API into
102106

103107
![Unity Playtesters Login Demo](assets/unity-login-integration-demo.gif)
104108

105-
## 📘 HTTP Request Examples
109+
### Scripts
110+
We provide two ready-to-use scripts in `assets/unity/`:
106111

107-
You can use this [Playtesters.API.http](https://github.com/DevD4v3/Playtesters.API/blob/master/src/Playtesters.API.http) file (VS Code / Rider / Visual Studio compatible) to test every endpoint of the API.
112+
1. **TesterLoginMenu.cs** – Handles tester login and access key validation.
113+
- Sends the access key entered by the tester to the `/api/testers/validate-access` endpoint.
114+
- Handles success and error responses from the API, including invalid keys and server errors.
115+
- Implements a **cooldown mechanism** after a configurable number of failed attempts.
116+
- On successful login, triggers the `PlaytimeReporter` to start reporting playtime and can load the main menu or other gameplay scenes.
117+
- Fully integrates with Unity UI using `TMP_InputFields` and `TMP_Text` for user feedback.
118+
119+
2. **PlaytimeReporter.cs** – Reports playtime increments to the backend.
120+
- Sends the number of hours played **since the last report** to `/api/testers/{accessKey}/playtime`.
121+
- The script **does not send the total playtime since login**, because the backend already keeps a record of total accumulated playtime.
122+
Sending the total from the start of the session would **double-count** the time.
123+
- Each report calculates the time difference from the last report (`_lastReportTime`) and updates `_lastReportTime` after sending.
124+
- By default, reports are sent every 2 minutes (`_reportIntervalSeconds`), but this can be configured via the Inspector.
125+
- Can be attached to a persistent GameObject (`DontDestroyOnLoad`) so it continues reporting across scenes.
126+
127+
128+
You can find them here:
129+
- [TesterLoginMenu.cs](assets/unity/TesterLoginMenu.cs)
130+
- [PlaytimeReporter.cs](assets/unity/PlaytimeReporter.cs)
108131

109132
## 📄License
110133

0 commit comments

Comments
 (0)