136 lines
5.4 KiB
C#
136 lines
5.4 KiB
C#
using System;
|
|
using I2.Loc;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine;
|
|
|
|
namespace MyGame.Scripts
|
|
{
|
|
public class GetRewardDialog : MonoBehaviour
|
|
{
|
|
private enum RewardType
|
|
{
|
|
Coin,
|
|
CornField,
|
|
IncreaseCustomer,
|
|
PerfectPopcorn
|
|
}
|
|
private static readonly string OkCallbackTag = "GetRewardDialogOkCallbackTag";
|
|
private static readonly string RewardTypeTag = "GetRewardDialogRewardTypeTag";
|
|
|
|
private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger");
|
|
private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger");
|
|
|
|
[Space]
|
|
[SerializeField] private Animator backgroundAnimator;
|
|
[SerializeField] private Button closeButton;
|
|
[SerializeField] private Button okButton;
|
|
[SerializeField] private Text messageText;
|
|
[SerializeField] private Button narrowCloseButton;
|
|
[SerializeField] private Button narrowOkButton;
|
|
[SerializeField] private Text narrowMessageText;
|
|
[SerializeField] private GameObject normalWindow;
|
|
[SerializeField] private GameObject narrowWindow;
|
|
[SerializeField] private GameObject coinObject;
|
|
[SerializeField] private GameObject fertilizerObject;
|
|
[SerializeField] private GameObject publicityObject;
|
|
|
|
private void Start()
|
|
{
|
|
narrowWindow.SetActive(false);
|
|
coinObject.SetActive(false);
|
|
fertilizerObject.SetActive(false);
|
|
publicityObject.SetActive(false);
|
|
switch (LocalCacheManager.Load<RewardType>(RewardTypeTag))
|
|
{
|
|
case RewardType.Coin:
|
|
normalWindow.SetActive(true);
|
|
coinObject.SetActive(true);
|
|
messageText.text = ScriptLocalization.System.CoinMainMessage;
|
|
SetButtonAction(closeButton, okButton, AdManager.AD_PLACEMENT_COIN);
|
|
break;
|
|
case RewardType.CornField:
|
|
normalWindow.SetActive(true);
|
|
fertilizerObject.SetActive(true);
|
|
messageText.text = ScriptLocalization.System.CornFieldMessage;
|
|
SetButtonAction(closeButton, okButton, AdManager.AD_PLACEMENT_CORNFIELD);
|
|
break;
|
|
case RewardType.IncreaseCustomer:
|
|
normalWindow.SetActive(true);
|
|
publicityObject.SetActive(true);
|
|
messageText.text = ScriptLocalization.System.IncreaseCustomerMessage;
|
|
SetButtonAction(closeButton, okButton, AdManager.AD_PLACEMENT_CUSTOMER);
|
|
break;
|
|
case RewardType.PerfectPopcorn:
|
|
normalWindow.SetActive(true);
|
|
messageText.text = ScriptLocalization.System.PerfectPopcornMessage;
|
|
SetButtonAction(closeButton, okButton, AdManager.AD_PLACEMENT_PERFECT);
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
|
|
private void SetButtonAction(Button closeButton, Button okButton, string Placement)
|
|
{
|
|
closeButton.OnClickAsObservable().Take(1).Subscribe(_ =>
|
|
{
|
|
transform.parent.SetLocalScale(0);
|
|
backgroundAnimator.SetTrigger(CloseTrigger);
|
|
this.CallWaitForSeconds(.25f, () =>
|
|
{
|
|
TransitionManager.Instance.UnloadScene(GameScenes.WatchMovieCoin);
|
|
});
|
|
}).AddTo(this);
|
|
okButton.OnClickAsObservable().Take(1).Subscribe(_ =>
|
|
{
|
|
if (AdManager.Instance.IsLoadedRewardVideo())
|
|
{
|
|
AdManager.Instance.ShowRewardVideo(result =>
|
|
{
|
|
if (result)
|
|
{
|
|
GameDataManager.GameData.AddAdCount();
|
|
LocalCacheManager.Load<Action>(OkCallbackTag, null)?.Invoke();
|
|
LocalCacheManager.Remove(OkCallbackTag);
|
|
}
|
|
TransitionManager.Instance.UnloadScene(GameScenes.WatchMovieCoin);
|
|
}, Placement);
|
|
}
|
|
else
|
|
{
|
|
TransitionManager.Instance.LoadSceneAdditive(GameScenes.WatchMovieFailure);
|
|
TransitionManager.Instance.UnloadScene(GameScenes.WatchMovieCoin);
|
|
}
|
|
}).AddTo(this);
|
|
}
|
|
|
|
private static void ShowDialog(Action okCallback, RewardType rewardType)
|
|
{
|
|
LocalCacheManager.Save(OkCallbackTag, okCallback);
|
|
LocalCacheManager.Save(RewardTypeTag, rewardType);
|
|
TransitionManager.Instance.LoadSceneAdditive(GameScenes.WatchMovieCoin);
|
|
}
|
|
|
|
public static void ShowCoinDialog(Action okCallback)
|
|
{
|
|
ShowDialog(okCallback, RewardType.Coin);
|
|
}
|
|
|
|
public static void ShowCornFieldDialog(Action okCallback)
|
|
{
|
|
ShowDialog(okCallback, RewardType.CornField);
|
|
}
|
|
|
|
public static void ShowIncreaseCustomerDialog(Action okCallback)
|
|
{
|
|
ShowDialog(okCallback, RewardType.IncreaseCustomer);
|
|
}
|
|
|
|
public static void ShowPerfectPopcornDialog(Action okCallback)
|
|
{
|
|
ShowDialog(okCallback, RewardType.PerfectPopcorn);
|
|
}
|
|
}
|
|
} |