Pro_Unit

Gift

Apr 9th, 2020
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. using GameCore;
  4.  
  5. using UnityEngine;
  6. using UnityEngine.Analytics;
  7.  
  8. using Lean.Pool;
  9. using UnityEngine.Events;
  10.  
  11. namespace QuestEngine
  12. {
  13.     public class Gift : MonoBehaviour
  14.     {
  15.         [SerializeField] private RewardInfoScripableDecorator _reward;
  16.         [SerializeField] private GameEventIRewardInfo _getReward;
  17.         [SerializeField] private PlayAudodestructSoundAction _audio;
  18.         [SerializeField] private ADListener _ads;
  19.         [SerializeField] private GameObject _adsIcon;
  20.         public bool IsFirst { get; set; }
  21.         private bool _isGeted = false;
  22.         public UnityEvent OnGeted;
  23.         public UnityEvent OnIgnored;
  24.         private void OnEnable()
  25.         {
  26.             _isGeted = false;
  27.             _adsIcon.SetActive(!IsFirst);
  28.         }
  29.         public void OnGet()
  30.         {
  31.             _isGeted = true;
  32.             Analytics.SendEvent("Gift Taked", new Dictionary<string, object>() { { "Reward", _reward.name } });
  33.             _audio.Play(gameObject, IsFirst ? (UnityAction)OnVideoShowed : ShowVideo);
  34.  
  35.             OnIgnored.RemoveAllListeners();
  36.  
  37.             LeanPool.Despawn(this);
  38.         }
  39.  
  40.         private void ShowVideo() => _ads.Show("Gift", OnVideoShowed);
  41.  
  42.         private void OnVideoShowed()
  43.         {
  44.             Analytics.SendEvent("Gift Rewarded Video Showed", new Dictionary<string, object>() { { "Reward", _reward.name } });
  45.  
  46.             _getReward.Raise(_reward);
  47.             OnGeted.Invoke();
  48.         }
  49.  
  50.         public void OnPlayerIgonore(GameObject player)
  51.         {
  52.             if (_isGeted == false)
  53.             {
  54.                 OnIgnored.Invoke();
  55.                 LeanPool.Despawn(this);
  56.             }
  57.         }
  58.  
  59.     }
  60. }
Add Comment
Please, Sign In to add comment