modify scripts
This commit is contained in:
@ -36,6 +36,7 @@ namespace WordsToolkit.Scripts.GUI.Buttons.Boosts
|
||||
private bool isActive;
|
||||
private bool isAnimating;
|
||||
|
||||
protected override bool ShouldShowRewarded() => isRewarded && resourseToHoldBoost.GetValue() == 0;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
@ -70,6 +71,11 @@ namespace WordsToolkit.Scripts.GUI.Buttons.Boosts
|
||||
priceObject.gameObject.SetActive(false);
|
||||
countText.text = resourseToHoldBoost.GetValue().ToString();
|
||||
}
|
||||
else if (ShouldShowRewarded())
|
||||
{
|
||||
countTextObject.gameObject.SetActive(false);
|
||||
priceObject.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
countTextObject.gameObject.SetActive(false);
|
||||
@ -96,6 +102,10 @@ namespace WordsToolkit.Scripts.GUI.Buttons.Boosts
|
||||
{
|
||||
ActivateBoost();
|
||||
}
|
||||
else if (ShouldShowRewarded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// If not, consume from the regular resource
|
||||
else if (resourceManager.ConsumeWithEffects(resourceToPay, count))
|
||||
{
|
||||
@ -110,6 +120,13 @@ namespace WordsToolkit.Scripts.GUI.Buttons.Boosts
|
||||
UpdatePriceDisplay();
|
||||
}
|
||||
|
||||
protected override void ExecuteEvent()
|
||||
{
|
||||
if(isRewarded)
|
||||
resourseToHoldBoost.Add(1);
|
||||
base.ExecuteEvent();
|
||||
}
|
||||
|
||||
protected virtual void ActivateBoost(bool hideButtons = true)
|
||||
{
|
||||
isAnimating = true;
|
||||
|
||||
@ -17,6 +17,8 @@ using UnityEngine.UI;
|
||||
using VContainer;
|
||||
using WordsToolkit.Scripts.Audio;
|
||||
using WordsToolkit.Scripts.Enums;
|
||||
using WordsToolkit.Scripts.Popups.Reward;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
using WordsToolkit.Scripts.System;
|
||||
using WordsToolkit.Scripts.System.Haptic;
|
||||
|
||||
@ -32,31 +34,48 @@ namespace WordsToolkit.Scripts.GUI.Buttons
|
||||
public new ButtonClickedEvent onClick;
|
||||
private new Animator animator;
|
||||
public bool noSound;
|
||||
public bool isRewarded;
|
||||
private RewardedButtonHandler handler;
|
||||
private PointerEventData currentEventData;
|
||||
|
||||
private static bool blockInput;
|
||||
|
||||
protected virtual bool ShouldShowRewarded() => isRewarded;
|
||||
|
||||
public static CustomButton latestClickedButton;
|
||||
private IAudioService audioService;
|
||||
private IObjectResolver objectResolver;
|
||||
[Inject]
|
||||
public void Construct(IAudioService audioService)
|
||||
public void Construct(IAudioService audioService, IObjectResolver objectResolver)
|
||||
{
|
||||
this.audioService = audioService;
|
||||
this.objectResolver = objectResolver;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
isClicked = false;
|
||||
// run only in runtime
|
||||
if (ShouldShowRewarded() && !GetComponent<RewardedButtonHandler>() && Application.isPlaying)
|
||||
{
|
||||
handler = gameObject.AddComponent<RewardedButtonHandler>();
|
||||
objectResolver.Inject(handler);
|
||||
var adReference = UnityEditor.AssetDatabase.LoadAssetAtPath<AdReference>("Assets/WordConnectGameToolkit/Prefabs/ScriptableAds/AdsTypes/Rewarded.asset");
|
||||
handler.adReference = adReference;
|
||||
handler.onRewardedAdComplete = new UnityEngine.Events.UnityEvent();
|
||||
handler.onRewardedAdComplete.AddListener(ExecuteEvent);
|
||||
}
|
||||
if (Application.isEditor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnEnable();
|
||||
animator = GetComponent<Animator>();
|
||||
if (overrideAnimatorController != null)
|
||||
{
|
||||
animator.runtimeAnimatorController = overrideAnimatorController;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void OnPointerClick(PointerEventData eventData)
|
||||
@ -66,6 +85,17 @@ namespace WordsToolkit.Scripts.GUI.Buttons
|
||||
return;
|
||||
}
|
||||
|
||||
currentEventData = eventData;
|
||||
|
||||
if (ShouldShowRewarded())
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
handler.ShowRewardedAd();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (transition != Transition.Animation)
|
||||
{
|
||||
Pressed();
|
||||
@ -75,7 +105,6 @@ namespace WordsToolkit.Scripts.GUI.Buttons
|
||||
if(!noSound)
|
||||
audioService.PlayClick(overrideClickSound);
|
||||
HapticFeedback.TriggerHapticFeedback(HapticFeedback.HapticForce.Light);
|
||||
// Start cooldown
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StartCoroutine(Cooldown());
|
||||
@ -91,8 +120,23 @@ namespace WordsToolkit.Scripts.GUI.Buttons
|
||||
return;
|
||||
}
|
||||
latestClickedButton = this;
|
||||
if (ShouldShowRewarded())
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
handler.ShowRewardedAd();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ExecuteEvent();
|
||||
}
|
||||
|
||||
protected virtual void ExecuteEvent()
|
||||
{
|
||||
onClick?.Invoke();
|
||||
EventManager.GetEvent<CustomButton>(EGameEvent.ButtonClicked).Invoke(this);
|
||||
base.onClick?.Invoke();
|
||||
}
|
||||
|
||||
private IEnumerator Cooldown()
|
||||
|
||||
Reference in New Issue
Block a user