Skip to content

Commit 09acb99

Browse files
committed
feat: add visual documentation
1 parent a8ff003 commit 09acb99

File tree

2 files changed

+268
-1
lines changed

2 files changed

+268
-1
lines changed

README.md

Lines changed: 268 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,268 @@
1-
1
1+
# AppLovin MAX Unity Demo
2+
3+
A Unity sample project demonstrating a clean, maintainable integration of **AppLovin MAX** for showing ads:
4+
- Banner ads
5+
- Interstitial ads
6+
- Two separate Rewarded ad units
7+
8+
![AppLovin MAX Unity Demo Screenshot in Unity Editor](images/applovin-demo-app.png)
9+
10+
The project implements **all listener and delegate methods** for each ad type — even if only for logging — so you can clearly see the lifecycle of ads and how to hook into them.
11+
12+
This project and documentation can be extended upon request. New features like Zenject demonstration, automated android version and similar useful implementation can be added.
13+
14+
---
15+
16+
## Features
17+
18+
### Ad Types Implemented
19+
- **Banner** – Toggle on/off, positioned via settings.
20+
- **Interstitial** – Fullscreen ad between content.
21+
- **Rewarded A & Rewarded B** – Two separate reward scenarios for testing.
22+
23+
### Listener Coverage
24+
25+
All relevant MAX callbacks are implemented and logged:
26+
27+
- **SDK**
28+
- `OnSdkInitializedEvent`
29+
- **Banner**
30+
- `OnAdLoadedEvent`
31+
- `OnAdLoadFailedEvent`
32+
- `OnAdClickedEvent`
33+
- `OnAdExpandedEvent`
34+
- `OnAdCollapsedEvent`
35+
- `OnAdRevenuePaidEvent`
36+
- **Interstitial**
37+
- `OnAdLoadedEvent`
38+
- `OnAdLoadFailedEvent`
39+
- `OnAdDisplayedEvent`
40+
- `OnAdDisplayFailedEvent`
41+
- `OnAdClickedEvent`
42+
- `OnAdHiddenEvent`
43+
- `OnAdRevenuePaidEvent`
44+
- **Rewarded**
45+
- `OnAdLoadedEvent`
46+
- `OnAdLoadFailedEvent`
47+
- `OnAdDisplayedEvent`
48+
- `OnAdDisplayFailedEvent`
49+
- `OnAdClickedEvent`
50+
- `OnAdHiddenEvent`
51+
- `OnAdReceivedRewardEvent`
52+
- `OnAdRevenuePaidEvent`
53+
54+
---
55+
56+
## Project Structure and Script Descriptions
57+
58+
### Scripts/Max/
59+
60+
* **[MaxInitializer.cs](Assets/Scripts/Max/MaxInitializer.cs)**
61+
62+
- Initializes the MAX SDK once at app start and survives scene loads (DontDestroyOnLoad).
63+
- Optional switches for verbose logging and test device IDs (must be set before InitializeSdk).
64+
- Subscribes to MaxSdkCallbacks.OnSdkInitializedEvent and is the single place to kick off ad loading via MaxAdsService.
65+
- Editor-safe: can expose a helper to open the Mediation Debugger on device.
66+
- Common pitfalls it prevents: calling load/show before the SDK is initialized.
67+
68+
* **[MaxAdService.cs](Assets/Scripts/Max/MaxAdService.cs)**
69+
70+
- A small facade singleton that owns all ad controllers and exposes a tiny UI API:
71+
- ToggleBanner(),
72+
- ShowInterstitial(),
73+
- ShowRewardedA(),
74+
- ShowRewardedB().
75+
76+
- Accepts a MaxAdSettings asset (ScriptableObject) so no IDs are hard-coded.
77+
- Subscribes once and guards against double registration (e.g., scene reloads).
78+
- Raises a simple ready signal after MAX init so UI can wire listeners safely.
79+
- Ideal place to later route impression revenue to analytics/MMPs (kept out of controllers).
80+
81+
* **[BannerAdController.cs](Assets/Scripts/Max/BannerAdController.cs)**
82+
83+
- Creates/configures a banner via AdViewConfiguration (position + background color).
84+
- Handles load/show/hide/toggle and logs all supported banner callbacks:
85+
- OnAdLoaded,
86+
- OnAdLoadFailed,
87+
- OnAdClicked,
88+
- OnAdExpanded,
89+
- OnAdCollapsed,
90+
- OnAdRevenuePaid.
91+
92+
* **[InterstitialAdController.cs](Assets/Scripts/Max/InterstitialAdController.cs)**
93+
94+
- Manages full-screen interstitials: preload → show → preload next.
95+
- Implements exponential backoff retry on load failures (1–64s).
96+
97+
- Logs all interstitial callbacks:
98+
- OnAdLoaded,
99+
- OnAdLoadFailed,
100+
- OnAdDisplayed,
101+
- OnAdDisplayFailed,
102+
- OnAdClicked,
103+
- OnAdHidden,
104+
- OnAdRevenuePaid.
105+
- Public API:
106+
- Initialize(adUnitId),
107+
- Preload(),
108+
- Show().
109+
110+
* **[RewardedAdController.cs](Assets/Scripts/Max/RewardedAdController.cs)**
111+
112+
- Same lifecycle as interstitials, plus the reward flow.
113+
- Logs all rewarded callbacks:
114+
- OnAdLoaded,
115+
- OnAdLoadFailed,
116+
- OnAdDisplayed,
117+
- OnAdDisplayFailed,
118+
- OnAdClicked,
119+
- OnAdHidden,
120+
- OnAdReceivedReward,
121+
- OnAdRevenuePaid.
122+
123+
- Exposes **OnRewardGranted** event so game code (e.g., “skip question”, coins) can react without touching ad logic.
124+
- Instantiated twice by MaxAdsService for Rewarded A and Rewarded B ad units.
125+
126+
### Scripts/Configs/
127+
128+
* **[MaxAdSettings.cs](Assets/Scripts/Config/MaxAdSettings.cs)**
129+
130+
- ScriptableObject that centralizes ad configuration:
131+
132+
- Android Ad Unit IDs:
133+
- Banner,
134+
- Interstitial,
135+
- Rewarded A and Rewarded B
136+
- Banner position and background color
137+
- Whether the banner starts hidden
138+
- Create multiple assets (e.g., Dev, Staging, Prod) and swap them without changing code.
139+
140+
### Scripts/UI/
141+
142+
* **[MediationButton.cs](Assets/Scripts/UI/MediationButton.cs)**
143+
144+
- Tiny helper to open the Mediation Debugger on device.
145+
- Add to any UI button; useful for enabling Test Ads quickly and inspecting integrations.
146+
147+
* **[ResourceLabel.cs](Assets/Scripts/UI/ResourceLabel.cs)**
148+
149+
- Binds a label to a resource value (e.g., coins), subscribing to updates from ResourcesController.
150+
- Keeps the UI in sync when rewards are granted—great for demos/screenshots.
151+
152+
* **[AdButtonsBinder.cs](Assets/Scripts/UI/AdButtonsBinder.cs)**
153+
154+
- Optional runtime wiring: attaches button onClick handlers after MaxAdsService reports ready.
155+
- Prevents double listeners and logs wiring, so you don’t need to set OnClick in the Inspector.
156+
157+
### Scripts/Resources/
158+
159+
* **[ResourceA/B + Receivers](Assets/Scripts/Resources/Resources.cs)**
160+
161+
- Minimal “reward sinks” to demonstrate integrating ads with game state.
162+
- Each resource tracks a value (e.g., “Coins A/B”).
163+
164+
* **[ResourcesController.cs](Assets/Scripts/Resources/ResourcesController.cs)**
165+
166+
- Listens to RewardedAdController.OnRewardGranted and applies the corresponding reward to the selected resource(s).
167+
- Updates any SimpleResourceLabel listeners and can persist via PlayerPrefs (optional).
168+
- Keeps gameplay concerns (state/UI) decoupled from ad concerns (loading/showing/listening).
169+
170+
***
171+
172+
## How It Works
173+
174+
1. **[Initialization](Assets/Scripts/Max/MaxInitializer.cs)**
175+
- `MaxInitializer` runs at startup.
176+
- Calls `MaxSdk.InitializeSdk()` and logs SDK details.
177+
178+
2. **[Ad Service](Assets/Scripts/Max/MaxAdService.cs)**
179+
- `MaxAdsService` creates and initializes controllers for
180+
- Banner,
181+
- Interstitial,
182+
- Rewarded A, and Rewarded B.
183+
- Preloads all ads on initialization as suggested.
184+
- Exposes simple methods:
185+
- `ToggleBanner()`,
186+
- `ShowInterstitial()`,
187+
- `ShowRewardedA()`,
188+
- `ShowRewardedB()`.
189+
190+
3. **Controllers**
191+
- Each ad type has its own controller:
192+
- [BannerAdController](Assets/Scripts/Max/BannerAdController.cs),
193+
- [InterstitialAdController](Assets/Scripts/Max/InterstitialAdController.cs),
194+
- [RewardedAdController](Assets/Scripts/Max/RewardedAdController.cs).
195+
- Subscribes to **all** MAX events and logs them.
196+
- Includes retry logic for failed loads (Interstitial & Rewarded).
197+
- Banner appearance and placement is configurable via [MaxAdSettings](Assets/Scripts/Config/MaxAdSettings.cs).
198+
199+
4. **Rewards**
200+
- [ResourcesController](Assets/Scripts/Resources/ResourcesController.cs) listens to `OnAdReceivedRewardEvent`.
201+
- Matches ad unit IDs to **ResourceA** or **ResourceB**.
202+
- Grants rewards (with fallback amounts if `reward.Amount` is 0).
203+
- [ResourceLabel](Assets/Scripts/UI/ResourceLabel.cs) updates UI automatically when resource values change.
204+
205+
5. **UI Binding**
206+
- [AdButtonsBinder](Assets/Scripts/UI/AdButtonsBinder.cs) connects Unity UI Buttons to ad service methods once `MaxAdsService` is ready.
207+
- [MediationButton](Assets/Scripts/UI/MediationButton.cs) opens the Mediation Debugger.
208+
209+
210+
## Setup
211+
212+
1. **Get Ad Unit IDs**
213+
- In the MAX dashboard, create:
214+
- 1x Banner
215+
- 1x Interstitial
216+
- 2x Rewarded
217+
- Assign them to [MaxAdSettings](Assets/Scripts/Config/MaxAdSettings.cs) in the Unity Inspector.
218+
219+
2. **Test Device**
220+
- (Optional) Find your GAID and enter it in `MaxInitializer.testDeviceGAID` to enable test ads.
221+
- Additionally, set your device as a test device using the Mediation Debugger.
222+
223+
3. **Run**
224+
- Open the demo scene.
225+
- Press Play.
226+
- Use the buttons to trigger ads and watch logs in the Console.
227+
228+
---
229+
230+
## Extending This Demo
231+
232+
- **New Rewarded Ads**: Add new fields in `MaxAdSettings` and handle them in `ResourcesController`.
233+
- **Different Reward Logic**: Replace `ResourceA/B` with your own reward systems.
234+
- **Custom UI**: Replace `AdButtonsBinder` with your own game UI integration.
235+
236+
---
237+
238+
## Debugging Tools
239+
240+
- **Mediation Debugger** – Use the “Open Mediation Debugger” button to inspect network setup.
241+
- **Verbose Logging** – Toggle in `MaxInitializer` to see detailed logs.
242+
- **Event Logs** – All ad lifecycle events are logged with `[Banner]`, `[Interstitial]`, `[Rewarded]` tags.
243+
244+
---
245+
246+
## Automated Versioning
247+
248+
This repo includes automated versioning and continuous integration setup, so commit on main branch triggers version bumping without the need for manual actions.
249+
250+
* Automated Versioning – Uses semantic-release to bump version numbers, generate changelogs, and tag releases based on commit history.
251+
252+
- Why it matters – Ensures that demo builds shared with clients are always reproducible, versioned, and match the code in the repo.
253+
254+
## License
255+
256+
This sample is for demonstration purposes.
257+
258+
**Logo / Branding Notice:**
259+
The application icon and any sample branding used in this demo **do not belong to me**. They are included **solely to improve UX and presentation** for demonstration purposes. All trademarks, service marks, and logos remain the property of their respective owners. No affiliation or endorsement is implied. If you are a rights holder and would like any asset removed, please contact me and I will take it down immediately.
260+
261+
## Author & Asset Attribution
262+
263+
**Developer:** Alp Kurt, Berlin, Germany
264+
265+
krtalp@gmail.com
266+
267+
If you have questions about this demo or the implementation details, feel free to reach out.
268+

images/applovin-demo-app.png

73.3 KB
Loading

0 commit comments

Comments
 (0)