Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnityAdsExampleUI.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class UnityAdsExampleUI : MonoBehaviour
  7. {
  8. public UnityAdsManager unityAdsManager;
  9. public Button initBtn;
  10. public Button loadRewardedBtn;
  11. public Button showRewardedBtn;
  12. public Button loadInterstitialBtn;
  13. public Button showInterstitialBtn;
  14. public Button toggleBannerBtn;
  15. public Text debugLogText;
  16. private string textLog = "DEBUG LOG: \n";
  17. private void Awake()
  18. {
  19. //if you didn't assign in the inspector
  20. if (unityAdsManager == null)
  21. {
  22. unityAdsManager = FindObjectOfType<UnityAdsManager>();
  23. }
  24. }
  25. private void Start()
  26. {
  27. initBtn.onClick.AddListener(unityAdsManager.Initialize);
  28. initBtn.onClick.AddListener(()=> debugLogText.text = "DEBUG LOG: \n");
  29. loadRewardedBtn.onClick.AddListener(unityAdsManager.LoadRewardedAd);
  30. showRewardedBtn.onClick.AddListener(unityAdsManager.ShowRewardedAd);
  31. loadInterstitialBtn.onClick.AddListener(unityAdsManager.LoadNonRewardedAd);
  32. showInterstitialBtn.onClick.AddListener(unityAdsManager.ShowNonRewardedAd);
  33. toggleBannerBtn.onClick.AddListener(unityAdsManager.ToggleBanner);
  34. }
  35. private void OnEnable()
  36. {
  37. UnityAdsManager.OnDebugLog += HandleDebugLog;
  38. }
  39. private void OnDisable()
  40. {
  41. UnityAdsManager.OnDebugLog -= HandleDebugLog;
  42. }
  43. void HandleDebugLog(string msg)
  44. {
  45. textLog += "\n" + msg + "\n";
  46. debugLogText.text = textLog;
  47. }
  48. }