# AdPlay Unity SDK Integration Prompt

Give this prompt to the coding assistant that has access to the target Unity project. Fill in the inputs you know; the assistant must inspect or ask about the rest.

```text
Act as a Unity integration engineer. Integrate the supplied AdPlay advertising SDK into this game and verify the result. Use the supplied SDK source and official guide as the authority for SDK behavior. Do not invent APIs, backend contracts, monetization rules, attribution, or supported platforms.

INPUTS
- Unity project root: [PROJECT_PATH]
- SDK package: [ADPLAY_UNITYPACKAGE_PATH]
- Official quick-start guide: https://adplay.ir/dev-source/fa/quick-start.html
- Additional developer guide, if provided: [GUIDE_PATH]
- Target platforms and build configurations: [TARGETS]
- Requested formats: [Splash / Banner / Popup / PopupButton / InterstitialSound]
- Placement requirements: [SCENE, UI LOCATION, TRIGGER, DISMISSAL, FREQUENCY]
- Game-specific publisher App Key: [CONFIGURED LOCALLY; NEVER PRINT IT]
- Authorized SDK source repairs: [YES / NO; DEFAULT NO]
- Test campaign or developer-provided test configuration: [DETAILS OR UNKNOWN]
- Performance budgets, if known: [STARTUP TIME, MEMORY, FRAME TIME, DOWNLOAD SIZE]

WORKING RULES
1. Inspect before editing. Preserve existing work and limit changes to integration requirements.
2. Identify which claims come from SDK source, the supplied guide, or your own integration decisions. Report conflicts instead of silently resolving them by inventing behavior.
3. Do not change unrelated gameplay, economy, save data, authentication, networking, rendering, or other SDKs.
4. Never expose tokens in logs, generated prompts, screenshots, or reports. Do not use an administrative token as the publisher App Key. Report how the project stores configuration and apply its existing credential-handling conventions.
5. Run only tools available in the environment. If Unity import, scene editing, device testing, or backend verification is unavailable, complete independent work and state the exact remaining manual actions. Never claim those actions were performed.
6. Do not fabricate test endpoints, test App Keys, test creatives, or revenue values. Do not submit fake engagement events to production.
7. Ask for missing product decisions that materially affect gameplay: placements, interruption points, audio permission, dismissal, and frequency. Continue independent inspection while awaiting answers.

PHASE 1: INSPECT THE GAME
- Read local project instructions and check version control changes.
- Read ProjectSettings/ProjectVersion.txt and Packages/manifest.json; inspect assembly definitions, scripting backend, stripping settings, platform plugins, and existing UI/text packages.
- Identify bootstrap, menu, gameplay, loading, pause, results, and scene-transition flows. Inspect additive scenes, persistent objects, object pools, and dependency injection if present.
- Identify Canvas ownership, render modes, scaling, safe-area handling, orientation, localization, RTL support, EventSystem, and input module.
- Identify existing ads, mediation, analytics, attribution, consent handling, audio mixer, mute settings, save/economy logic, and online/offline behavior.
- Map each requested placement to an explicit game event. Do not insert ads into every scene merely because the SDK exists.
- Report unresolved compatibility and placement decisions before dependent edits.

PHASE 2: INSPECT THE EXACT SDK
- Inspect package paths and C# source before importing; preserve Unity GUIDs and .meta files.
- Confirm dependencies rather than choosing arbitrary versions. This inspected package references Unity UI, RTLTMPro, Newtonsoft.Json, and Android's Google Play advertising-ID class.
- Check whether those dependencies already exist. The package bundles Newtonsoft.Json.dll; prevent duplicate Newtonsoft assemblies. Do not remove a dependency used by the game without establishing a compatible solution.
- The published quick-start supplies RTLTMPro at https://github.com/hk1ll3r/RTLTMPro.git?path=/UPMPackage with package ID com.nosuchstudio.rtltmpro. Inspect compatibility and record the resolved revision; the guide does not pin a version. If installation needs network access unavailable in the target environment, report the dependency as blocked rather than pretending it is installed.
- Establish Unity compatibility from actual APIs and compilation. Directly awaiting UnityWebRequest operations and using FindAnyObjectByType/FindFirstObjectByType need compatibility checks. Do not assert a minimum Unity version without evidence.
- Inspect prefabs, serialized references, configuration assets, manager action mappings, and the sample scene. Confirm that format handlers are actually wired.
- Check Editor and player compilation paths, including conditional compilation.

KNOWN FACTS FROM THE INSPECTED PACKAGE; RECHECK IF THE PACKAGE CHANGES
- Imports under Assets/Adplay.
- Namespaces include Adplay.Behaviours, Adplay.View, and Adplay.Model.
- AdPlayManager initializes in Awake and uses DontDestroyOnLoad.
- Public methods include Initialize(), GetSplash(template), GetBanner(template), GetPopUp(template), GetPopUpButton(template, Action), and GetInterstitialSound().
- Ad methods return Task<AdRequestInfo>; inspect IsSuccess, State, and ErrorMessage.
- OnGetAdsComplete is a success notification, not a general completion/failure notification. There is no public initialized-state getter in this package.
- AdPlayTemplate uses Image, Button, RectTransform, and RTLTextMeshPro references. Required references differ by format.
- Editor menu paths in this package are Window/Ad Play/App key and Window/Ad Play/Spawn Prefab.
- The quick-start writes Windows -> Ad Play -> App Key. The inspected editor source uses Window/Ad Play/App key; follow the actual installed menu and report this documentation mismatch.
- Production API base is https://addata.ir/; Editor configuration can select a local route. Confirm the correct route before testing.
- The App Key is sent as Authorization: Token <key>.
- Ad retrieval posts to ad/show-ads; engagement delivery posts to data/engagement/batch.
- Public IP retrieval calls https://api.ipify.org.
- Image creatives and interstitial audio have implementation. Video enum values exist, but video-loading branches are empty. Do not offer video or rewarded-video integration.
- Image cache stores PNG bytes serialized into PlayerPrefs JSON. There is no documented adaptive-resolution mechanism, cache budget, or durable offline event queue in this package.
- Popup handles click reporting and opens the creative ClickUrl. Banner and splash must not be assumed to have equivalent click behavior.
- Engagement reporting is owned by the SDK. Do not duplicate it in game glue code.

RELEASE ISSUES TO CHECK BEFORE DECLARING SUCCESS
- EngagementData.cs has a class-closing brace within UNITY_EDITOR conditional compilation in the inspected package, potentially breaking player compilation.
- Http POST methods attach BypassCertificate, whose validation accepts all certificates.
- AdPlayPopUpButton checks for both creatives being absent, then can dereference a missing popup-button creative.
- Event uploads are immediate single-event requests with no durable retry queue. Duration updates occur after initial delivery and are not automatically resent.
- Initialization exception handling can leave initialization state stuck; retries are bounded and concurrent initialization is not explicitly guarded.
- Android advertising-ID retrieval is synchronous; validate dependencies and device behavior. No iOS advertising-ID implementation was found in this helper.
If authorized to repair SDK source, make narrowly scoped, documented repairs and validate them. Otherwise report blockers and continue independent integration preparation. Do not silently ship a workaround that leaves a build or certificate blocker unresolved. Event retry, deduplication, and duration-contract changes require backend agreement; do not invent server support.

PHASE 3: IMPORT AND CONFIGURE
- Import using available Unity tooling; maintain the SDK's original asset references.
- Resolve dependencies through the game's established package/plugin workflow. Identify any required downloads and their verified versions.
- Configure the game-specific App Key using the existing ApiConfigData asset and documented workflow. Confirm the manager/request refer to that asset.
- Place a single manager in the bootstrap lifecycle. Do not create a manager for every scene.
- Check startup scenes, direct gameplay-scene runs, additive loading, existing persistent objects, and duplicate-manager handling.
- Do not call Initialize a second time automatically while Awake is already initializing.
- Confirm production/development routing without logging credentials.

PHASE 4: IMPLEMENT GAME INTEGRATION
- Use a small adapter/controller that matches existing architecture. Keep business rules in the game and creative/tracking behavior in the SDK.
- Subscribe to OnGetAdsComplete before manager initialization where possible; unsubscribe correctly. Since the SDK does not replay readiness or expose a public state getter, handle late-created UI explicitly using existing architecture or an authorized SDK change. Never wait forever for an already-fired event.
- Keep gameplay usable when initialization fails, ads are absent, or networking is slow. Readiness does not guarantee a creative exists for a particular format.
- Prefer Task-returning internal methods. Use async void only at required Unity/button boundaries and catch exceptions there.
- Prevent repeated taps and concurrent requests for the same placement.
- Instantiate a separate AdPlayTemplate for each displayed placement. Avoid listener accumulation when reusing templates.
- Handle all actual AdRequestInfo states and exceptions. Clean up failed/obsolete template instances.
- Handle scene changes, destroyed UI, app pause/resume, and application shutdown while requests are pending. The current SDK has no cancellation API; a timeout in game glue does not cancel SDK work. Prevent late results from resurrecting obsolete UI without claiming requests were cancelled.
- Implement dismissal and pause/timeScale rules only according to the game's requirements. The SDK does not provide a public ad-close or reward-completion API; do not fabricate one.
- For popup-button flows, use the Action callback to request the popup and handle failure independently. Catch exceptions from asynchronous callback work.
- Preserve mute and audio-mixer behavior for approved audio placements. Confirm AudioSource and AudioListener references. Do not play audio when only image placements were requested.
- Inspect initialization's actual requested/downloaded types: hiding audio calls in game code alone does not guarantee an image-only SDK or image-only downloads. Report any required capability filtering as a separate SDK/backend change.
- Do not grant currency or rewards merely because GetAd returns Success. No verified reward-completion contract exists here.

PHASE 5: PRESENTATION AND RESOURCE HANDLING
- Keep templates within the correct Canvas and sorting/input hierarchy. Respect safe areas, aspect ratios, orientation, localization, and existing accessibility conventions.
- Preserve image aspect ratio according to placement requirements; distinguish source image resolution from UI dimensions. Do not claim automatic bandwidth-based resolution selection.
- Use layout tests to ensure no clipping, accidental gameplay-input interception, or inaccessible controls.
- Review native Texture2D/Sprite/AudioClip ownership. Do not destroy SDK-owned shared assets from placement glue.
- Measure startup download/cache work, frame-time impact, managed/native memory, repeated placements, and scene transitions against supplied budgets.
- Report that cached images do not imply offline startup: this package still fetches active creatives before populating active ads.
- Confirm needed API, IP lookup, and creative hosts from actual configuration/responses. Do not invent an asset-host allowlist.

PHASE 6: TRACKING AND PLATFORM VALIDATION
- Verify the SDK's own impression/click/audio events with an approved test environment and redacted logs. Check actual backend receipt when access exists.
- Do not interpret impression creation as proof of screen visibility, a conversion, or settled publisher revenue.
- Note zero-valued placeholder fields and that deviceModel currently holds Unity's device identifier. Do not silently treat them as measured data.
- Confirm platform identity, advertising-ID availability, platform dependencies, consent requirements provided by the developer, and behavior when identifiers are unavailable. Do not invent an AdTrace integration.
- Check final player compilation, IL2CPP/AOT and stripping where applicable, Android dependency resolution/manifest merge, and iOS build/plugin requirements where applicable.
- Confirm that Editor-only code and samples do not compromise player builds. Do not assume Editor success proves Android/iOS support.

PHASE 7: VERIFY
Run the relevant checks available for the chosen targets:
1. Clean Editor compilation and target player build.
2. Startup success, delayed response, initialization failure, and late-created UI.
3. Every requested format with valid creatives, missing creatives, and missing template references.
4. Offline launch, network loss during downloads/uploads, and reconnect behavior.
5. Rapid repeated taps, scene transitions during requests, additive scenes, and repeated entry/exit.
6. Placement sizing across target aspect ratios/orientations and RTL/LTR locales.
7. Audio mute/pause behavior if audio is approved.
8. Approved test impression/click receipt, absence of duplicated glue-code tracking, and failed-delivery limitations.
9. Repeated-placement memory/frame-time checks and cleanup.
10. Existing game smoke tests: startup, gameplay, pause, saves, purchases, and other SDK initialization where affected.
Use focused tests that exercise observable behavior. Record actual failures and unavailable checks; never invent passing results.

DELIVERABLES
- Implemented integration and exact changed-file list.
- Placement map: game event, format, template, initialization dependency, dismissal, and failure behavior.
- Dependency/version and platform compatibility findings.
- Redacted configuration instructions and any remaining Unity Editor actions.
- Test report separating passed, failed, blocked, and not run.
- SDK defects with file/line evidence and distinction between repaired and unresolved issues.
- Release verdict: ready only for targets and workflows actually verified; otherwise list specific blockers.
- Short maintenance notes covering SDK updates, duplicate dependencies, configuration, and backend assumptions.
Complete the authorized work. Do not declare integration finished merely because scripts were generated.
```
