ads added
This commit is contained in:
@@ -6,8 +6,10 @@ using Darkmatter.Core;
|
||||
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
|
||||
using Darkmatter.Core.Contracts.Features.Loading;
|
||||
using Darkmatter.Core.Contracts.Features.Progression;
|
||||
using Darkmatter.Core.Contracts.Services.Ads;
|
||||
using Darkmatter.Core.Contracts.Services.Scenes;
|
||||
using Darkmatter.Core.Data.Signals.Features.Drawing;
|
||||
using Darkmatter.Core.Enums.Services.Ads;
|
||||
using Darkmatter.Core.Enums.Services.Scenes;
|
||||
using Darkmatter.Libs.Observer;
|
||||
using VContainer.Unity;
|
||||
@@ -20,33 +22,54 @@ public class ColorbookFlowController : IAsyncStartable, IDisposable
|
||||
private readonly ILoadingScreen _loadingScreen;
|
||||
private readonly IProgressionSystem _progression;
|
||||
private readonly ISceneService _scenes;
|
||||
private readonly IAdService _ads;
|
||||
private readonly IEventBus _bus;
|
||||
|
||||
private IDisposable _selectedSub;
|
||||
private IDisposable _returnToMainMenuSubscription;
|
||||
private bool _navigatingToGameplay;
|
||||
private CancellationTokenSource _scopeCts;
|
||||
|
||||
public ColorbookFlowController(
|
||||
IDrawingCatalogController drawingCatalog,
|
||||
ILoadingScreen loadingScreen,
|
||||
IProgressionSystem progression,
|
||||
ISceneService scenes,
|
||||
IAdService ads,
|
||||
IEventBus bus)
|
||||
{
|
||||
_drawingCatalog = drawingCatalog;
|
||||
_loadingScreen = loadingScreen;
|
||||
_progression = progression;
|
||||
_scenes = scenes;
|
||||
_ads = ads;
|
||||
_bus = bus;
|
||||
_selectedSub = _bus.Subscribe<DrawingSelectedSignal>(OnDrawingSelected);
|
||||
}
|
||||
|
||||
public async UniTask StartAsync(CancellationToken cancellation = new CancellationToken())
|
||||
{
|
||||
_scopeCts = CancellationTokenSource.CreateLinkedTokenSource(cancellation);
|
||||
_returnToMainMenuSubscription = _bus.Subscribe<ReturnToMainMenuSignal>(OnReturnToMainMenu);
|
||||
_loadingScreen.SetProgress(1f);
|
||||
await _drawingCatalog.InitializeAsync(cancellation);
|
||||
if (!_navigatingToGameplay) _loadingScreen.Hide();
|
||||
|
||||
PrewarmRewardedAdAsync(_scopeCts.Token).Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid PrewarmRewardedAdAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_ads.IsInitialized) await _ads.InitializeAsync(ct);
|
||||
if (!_ads.IsReady(AdFormat.Rewarded)) await _ads.LoadAsync(AdFormat.Rewarded, ct);
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[ColorbookFlow] Rewarded prewarm failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReturnToMainMenu(ReturnToMainMenuSignal signal)
|
||||
@@ -72,6 +95,10 @@ public class ColorbookFlowController : IAsyncStartable, IDisposable
|
||||
|
||||
private async UniTaskVoid HandleSelectionAsync(string templateId)
|
||||
{
|
||||
var ct = _scopeCts?.Token ?? CancellationToken.None;
|
||||
|
||||
await ShowRewardedAdAsync(ct);
|
||||
|
||||
_loadingScreen.Show();
|
||||
var progress = new Progress<float>(p => _loadingScreen.SetProgress(p * 0.5f));
|
||||
var mappedProgress = new Progress<float>(p => _loadingScreen.SetProgress(0.5f + p * 0.25f));
|
||||
@@ -81,9 +108,25 @@ public class ColorbookFlowController : IAsyncStartable, IDisposable
|
||||
cancellationToken: default);
|
||||
}
|
||||
|
||||
private async UniTask ShowRewardedAdAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_ads.IsInitialized) await _ads.InitializeAsync(ct);
|
||||
await _ads.ShowAsync(AdFormat.Rewarded, ct);
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[ColorbookFlow] Rewarded ad failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_selectedSub?.Dispose();
|
||||
_returnToMainMenuSubscription?.Dispose();
|
||||
_scopeCts?.Cancel();
|
||||
_scopeCts?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,14 @@ using Darkmatter.Core.Contracts.Features.GameplayFlow;
|
||||
using Darkmatter.Core.Contracts.Features.Loading;
|
||||
using Darkmatter.Core.Contracts.Features.Progression;
|
||||
using Darkmatter.Core.Contracts.Features.ShapeBuilder;
|
||||
using Darkmatter.Core.Contracts.Services.Audio;
|
||||
using Darkmatter.Core.Contracts.Services.Scenes;
|
||||
using Darkmatter.Core.Data.Dynamic.Features.Progression;
|
||||
using Darkmatter.Core.Data.Signals.Features.Coloring;
|
||||
using Darkmatter.Core.Data.Signals.Features.Drawing;
|
||||
using Darkmatter.Core.Data.Signals.Features.ShapeBuilder;
|
||||
using Darkmatter.Core.Enums.Features.Progression;
|
||||
using Darkmatter.Core.Enums.Services.Audio;
|
||||
using Darkmatter.Core.Enums.Services.Scenes;
|
||||
using Darkmatter.Libs.Observer;
|
||||
using UnityEngine;
|
||||
@@ -34,6 +36,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
|
||||
private readonly ICaptureFeature _capture;
|
||||
private readonly ILoadingScreen _loadingScreen;
|
||||
private readonly IGameplaySceneRefs _refs;
|
||||
private readonly ISfxPlayer _sfx;
|
||||
private readonly IEventBus _bus;
|
||||
|
||||
private IDrawingTemplate _template;
|
||||
@@ -55,6 +58,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
|
||||
ICaptureFeature capture,
|
||||
ILoadingScreen loadingScreen,
|
||||
IGameplaySceneRefs refs,
|
||||
ISfxPlayer sfx,
|
||||
IEventBus bus)
|
||||
{
|
||||
_progression = progression;
|
||||
@@ -65,6 +69,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
|
||||
_capture = capture;
|
||||
_loadingScreen = loadingScreen;
|
||||
_refs = refs;
|
||||
_sfx = sfx;
|
||||
_bus = bus;
|
||||
}
|
||||
|
||||
@@ -125,6 +130,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
|
||||
{
|
||||
await SaveCurrentAsync(ct);
|
||||
_refs.Confetti.Play();
|
||||
_sfx.Play(SfxId.LevelComplete);
|
||||
await _coloring.PlayCompletionAnimationAsync(ct);
|
||||
_progression.MarkCompleted(_templateId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user