Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GameCore;
- using GameCore.CrossPlatfomADMediator;
- using System;
- using UniRx;
- using Unity.Linq;
- using UnityEngine;
- using Text = TMPro.TextMeshProUGUI;
- namespace QuestEngine
- {
- public class RewardedAdsTimer : MonoBehaviour
- {
- [SerializeField] private Text _text;
- [SerializeField] private ADListener _ads;
- [SerializeField] private IntVariable _secondsFromWait;
- private TimeSpan _second = TimeSpan.FromSeconds(1);
- private TimeSpan _waitTime;
- private void Awake()
- {
- _waitTime = TimeSpan.FromSeconds(_secondsFromWait);
- Observable
- .Timer(_waitTime, _second)
- .Subscribe(new ObervableTimer(DisableText, UpdateText, error => DisableText()));
- }
- private void DisableText()
- {
- ActiveChids(false);
- }
- private void UpdateText(TimeSpan timer)
- {
- _text.text = timer.ToString(@"mm\:ss");
- }
- private void ActiveChids(bool active)
- {
- gameObject.Children().ForEach(go => go.SetActive(active));
- }
- }
- public class ObervableTimer : IObserver<long>
- {
- private readonly Action _onCompleted;
- private readonly Action<TimeSpan> _onUpdate;
- private readonly Action<Exception> _onError;
- public ObervableTimer(Action onCompleted, Action<TimeSpan> onUpdate = null, Action<Exception> onError = null)
- {
- _onCompleted = onCompleted;
- _onUpdate = onUpdate;
- _onError = onError;
- }
- public void OnCompleted()
- {
- _onCompleted?.Invoke();
- }
- public void OnError(Exception error)
- {
- _onError?.Invoke(error);
- }
- public void OnNext(long tiks)
- {
- _onUpdate?.Invoke(TimeSpan.FromTicks(tiks));
- }
- }
- }
Add Comment
Please, Sign In to add comment