87 lines
2.2 KiB
C#
87 lines
2.2 KiB
C#
|
using System.Collections;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace RND
|
|||
|
{
|
|||
|
|
|||
|
public enum EnumRewardResult { SKIP, FAIL, NEED_REWARD }
|
|||
|
|
|||
|
public delegate void RewardResult(EnumRewardResult result);
|
|||
|
|
|||
|
public abstract class BaseRewardSection : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField] private float _delayForShowingSkipButton = 3f;
|
|||
|
[SerializeField] private SkipButton _skipButton = null;
|
|||
|
|
|||
|
protected abstract RewardButton RewardButton { get; }
|
|||
|
|
|||
|
private Coroutine _skipButtonShowDelay;
|
|||
|
private RewardResult _resultCallback;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_skipButton.SetHandler(OnClickSkipButton);
|
|||
|
RewardButton.SetHandler(RewardButtonCallback);
|
|||
|
}
|
|||
|
|
|||
|
public void SetCallback(RewardResult callback) => _resultCallback = callback;
|
|||
|
public void SetPlacement(string placement) => RewardButton.SetPlacement(placement);
|
|||
|
|
|||
|
public void Begin()
|
|||
|
{
|
|||
|
#if APP_HAS_ADS
|
|||
|
RewardButton.Begin();
|
|||
|
ShowSkipButtonAfterTime();
|
|||
|
#else
|
|||
|
HideRewardButton();
|
|||
|
ShowSkipButtonImmediately();
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
public void HideRewardButton()
|
|||
|
{
|
|||
|
RewardButton.gameObject.Hide();
|
|||
|
}
|
|||
|
|
|||
|
public void Show()
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public void Hide()
|
|||
|
{
|
|||
|
gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
private void ShowSkipButtonImmediately()
|
|||
|
{
|
|||
|
_skipButton.ShowView();
|
|||
|
}
|
|||
|
|
|||
|
private void ShowSkipButtonAfterTime()
|
|||
|
{
|
|||
|
if (_skipButtonShowDelay != null)
|
|||
|
StopCoroutine(_skipButtonShowDelay);
|
|||
|
|
|||
|
_skipButtonShowDelay = StartCoroutine(ShowSkipButtonAfterTimeRoutine());
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator ShowSkipButtonAfterTimeRoutine()
|
|||
|
{
|
|||
|
_skipButton.HideView();
|
|||
|
yield return new WaitForSeconds(_delayForShowingSkipButton);
|
|||
|
_skipButton.ShowView();
|
|||
|
}
|
|||
|
|
|||
|
private void RewardButtonCallback(bool result)
|
|||
|
{
|
|||
|
_resultCallback?.Invoke(result ? EnumRewardResult.NEED_REWARD : EnumRewardResult.FAIL);
|
|||
|
}
|
|||
|
|
|||
|
private void OnClickSkipButton()
|
|||
|
{
|
|||
|
_resultCallback?.Invoke(EnumRewardResult.SKIP);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|