| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using UnityEngine;
- public partial class GameScreenView
- {
- PopViewScreenView popView;
- [SerializeField] GameObject popViewPanelPrefab;
- bool adPlaying;
- bool revivedThisLevel;
- string pendingFailTitle;
- string pendingFailSubtitle;
- public bool IsAdPlaying => adPlaying;
- void BuildPopView()
- {
- GameObject root = InstantiatePanel(popViewPanelPrefab, "Prefab/12_popview", "AdPopView");
- if (root == null)
- return;
- popView = root.GetComponent<PopViewScreenView>();
- if (popView == null)
- popView = root.AddComponent<PopViewScreenView>();
- }
- bool IsPopViewVisible()
- {
- return popView != null && popView.gameObject.activeSelf;
- }
- bool CanOfferAdRevive()
- {
- if (revivedThisLevel)
- return false;
- return SaveService.CanAdReviveToday();
- }
- void OfferAdRevive(string title, string subtitle)
- {
- if (popView == null)
- {
- ShowResult(false, title, subtitle);
- return;
- }
- pendingFailTitle = title;
- pendingFailSubtitle = subtitle;
- var content = new PopViewContent
- {
- Title = L.Get("pop.out_of_moves"),
- Badge = L.F("pop.ad_moves_badge", GameDefinitions.AdReviveMoveBonus),
- Body = L.Get("pop.ad_body"),
- ConfirmText = L.Get("pop.watch_ad"),
- CancelText = L.Get("pop.end_run")
- };
- popView.Show(content, OnAdReviveConfirmed, OnAdReviveDeclined);
- }
- void OnAdReviveDeclined()
- {
- ShowResult(false, pendingFailTitle, pendingFailSubtitle);
- }
- void OnAdReviveConfirmed()
- {
- adPlaying = true;
- AdMobService.ShowRewarded(
- AdPlacement.Revive,
- CompleteAdRevive,
- HandleAdReviveFailed);
- }
- void HandleAdReviveFailed(string reason)
- {
- adPlaying = false;
- Debug.LogWarning("[GameScreen] Ad revive failed: " + reason);
- ShowBanner(L.Get("pop.ad_not_ready"), 1.2f, 22f);
- OfferAdRevive(pendingFailTitle, pendingFailSubtitle);
- }
- void CompleteAdRevive()
- {
- adPlaying = false;
- revivedThisLevel = true;
- ended = false;
- busy = false;
- SaveService.RecordAdRevive();
- state.AddMoves(GameDefinitions.AdReviveMoveBonus);
- RefreshHud();
- GameAudio.PlaySfx(GameSfx.Buy);
- ShowBanner(L.F("pop.ad_moves_badge", GameDefinitions.AdReviveMoveBonus), 1.2f, 30f);
- }
- }
|