Advertisement
Pro_Unit

RepeatableBanner

Jan 20th, 2022 (edited)
763
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. using UnityEngine;
  6.  
  7. public class RepeatableBanner : MonoBehaviour
  8. {
  9.     [SerializeField]
  10.     private float _timeStep = 1f;
  11.  
  12.     [SerializeField]
  13.     private string _adUnitId = "YOUR_adUnitId";
  14.  
  15.     [SerializeField]
  16.     private AdSize _adSize = AdSize.BANNER_320x50;
  17.  
  18.     [SerializeField]
  19.     private AdPosition _adPosition = AdPosition.BottomCenter;
  20.  
  21.     [SerializeField]
  22.     private Parameter[] _parameters;
  23.  
  24.     private Banner banner;
  25.  
  26.     private void Start()
  27.     {
  28.         banner = new Banner(_adUnitId, _adSize, _adPosition);
  29.         StartCoroutine(StartRepeatTimer());
  30.     }
  31.  
  32.     private IEnumerator StartRepeatTimer()
  33.     {
  34.         while (true)
  35.         {
  36.             yield return new WaitForSeconds(_timeStep);
  37.  
  38.             RequestBanner();
  39.         }
  40.     }
  41.  
  42.     private void RequestBanner()
  43.     {
  44.         AdRequest request = new AdRequest.Builder().WithParameters(CreateAdFoxParameters()).Build();
  45.  
  46.         banner.LoadAd(request);
  47.     }
  48.  
  49.     // Код из интерфейса ADFOX для работы с прямыми кампаниями.
  50.     private Dictionary<string, string> CreateAdFoxParameters() =>
  51.         _parameters.ToDictionary(parameter => parameter.Name, parameter => parameter.Value);
  52.  
  53.     [System.Serializable]
  54.     public class Parameter
  55.     {
  56.         public string Name;
  57.         public string Value;
  58.     }
  59. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement