123 lines
No EOL
4 KiB
C#
123 lines
No EOL
4 KiB
C#
using ShiroginSDK.Runtime.Services.Base;
|
|
using ShiroginSDK.Runtime.Services.Interfaces;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace ShiroginSDK.Samples.ApplovinSample.Scripts
|
|
{
|
|
/// <summary>
|
|
/// Demonstrates how to manually trigger ad actions (Rewarded, Interstitial, Banner)
|
|
/// through the ShiroginSDK AdsService system.
|
|
/// </summary>
|
|
public class ApplovinSampleUI : MonoBehaviour
|
|
{
|
|
[Header("UI References")] [SerializeField]
|
|
private Button rewardedAdButton;
|
|
|
|
[SerializeField]
|
|
private Button interstitialAdButton;
|
|
|
|
[SerializeField]
|
|
private Button bannerAdCreateButton;
|
|
|
|
[SerializeField]
|
|
private Button bannerAdShowButton;
|
|
|
|
[SerializeField]
|
|
private Button bannerAdHideButton;
|
|
|
|
[SerializeField]
|
|
private Button bannerAdDestroyButton;
|
|
|
|
private IAdsService _adsService;
|
|
|
|
private void Awake()
|
|
{
|
|
_adsService = ServiceLocator.Get<IAdsService>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (rewardedAdButton) rewardedAdButton.onClick.AddListener(ShowRewardedAd);
|
|
if (interstitialAdButton) interstitialAdButton.onClick.AddListener(ShowInterstitialAd);
|
|
if (bannerAdCreateButton) bannerAdCreateButton.onClick.AddListener(CreateBannerAd);
|
|
if (bannerAdShowButton) bannerAdShowButton.onClick.AddListener(ShowBannerAd);
|
|
if (bannerAdHideButton) bannerAdHideButton.onClick.AddListener(HideBannerAd);
|
|
if (bannerAdDestroyButton) bannerAdDestroyButton.onClick.AddListener(DestroyBannerAd);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (rewardedAdButton) rewardedAdButton.onClick.RemoveAllListeners();
|
|
if (interstitialAdButton) interstitialAdButton.onClick.RemoveAllListeners();
|
|
if (bannerAdCreateButton) bannerAdCreateButton.onClick.RemoveAllListeners();
|
|
if (bannerAdShowButton) bannerAdShowButton.onClick.RemoveAllListeners();
|
|
if (bannerAdHideButton) bannerAdHideButton.onClick.RemoveAllListeners();
|
|
if (bannerAdDestroyButton) bannerAdDestroyButton.onClick.RemoveAllListeners();
|
|
}
|
|
|
|
#region Ad Controls
|
|
|
|
private void ShowRewardedAd()
|
|
{
|
|
if (_adsService == null)
|
|
{
|
|
Debug.LogError("[ApplovinSampleUI] ❌ AdsService not initialized.");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("[ApplovinSampleUI] ▶ Showing Rewarded Ad...");
|
|
_adsService.ShowRewarded(success =>
|
|
{
|
|
if (success)
|
|
Debug.Log("[ApplovinSampleUI] ✅ User watched full ad — reward granted.");
|
|
else
|
|
Debug.Log("[ApplovinSampleUI] ⚠️ User skipped or ad failed.");
|
|
});
|
|
}
|
|
|
|
private void ShowInterstitialAd()
|
|
{
|
|
if (_adsService == null)
|
|
{
|
|
Debug.LogError("[ApplovinSampleUI] ❌ AdsService not initialized.");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("[ApplovinSampleUI] ▶ Showing Interstitial Ad...");
|
|
_adsService.ShowInterstitial(true);
|
|
}
|
|
|
|
private void CreateBannerAd()
|
|
{
|
|
if (_adsService == null)
|
|
{
|
|
Debug.LogError("[ApplovinSampleUI] ❌ AdsService not initialized.");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("[ApplovinSampleUI] 🧱 Creating Banner...");
|
|
_adsService.CreateBanner(true);
|
|
}
|
|
|
|
private void ShowBannerAd()
|
|
{
|
|
_adsService?.ShowBanner();
|
|
Debug.Log("[ApplovinSampleUI] 📢 Banner shown.");
|
|
}
|
|
|
|
private void HideBannerAd()
|
|
{
|
|
_adsService?.HideBanner();
|
|
Debug.Log("[ApplovinSampleUI] 💤 Banner hidden.");
|
|
}
|
|
|
|
private void DestroyBannerAd()
|
|
{
|
|
_adsService?.DestroyBanner();
|
|
Debug.Log("[ApplovinSampleUI] 💣 Banner destroyed.");
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |