513 lines
14 KiB
C#
513 lines
14 KiB
C#
using Monetization.Runtime.Ads;
|
|
using MoreMountains.NiceVibrations;
|
|
using PimDeWitte.UnityMainThreadDispatcher;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LevelManager : MonoBehaviour
|
|
{
|
|
public static LevelManager instance;
|
|
|
|
public string levelPrefix = "Lv";
|
|
|
|
private GameObject currentLevelPrefab;
|
|
|
|
public static int currentLevel = 1;
|
|
|
|
[SerializeField]
|
|
private int maxLevels;
|
|
|
|
public int currentLevelNumberToShow = 1;
|
|
|
|
public Transform noThanksCoinPosTr;
|
|
|
|
public Transform GetDoubleRewardCoinTr;
|
|
|
|
private float rewardMultiplierCounter = 20f;
|
|
|
|
public Text rewardMultiplierText;
|
|
|
|
public int currentLevelCoinsEarned = 50;
|
|
|
|
public GameObject hintTutorialObj;
|
|
|
|
private static int lastHintsPanelShownLevel = -1;
|
|
|
|
[Header("No Panel Test — Button Refs")]
|
|
public GameObject noThanksBtn_Comp;
|
|
|
|
public GameObject retryBtn_Comp;
|
|
|
|
public GameObject skipBtn_Fail;
|
|
|
|
public GameObject retryBtn_Fail;
|
|
|
|
public Animator meterArrowAnimator;
|
|
|
|
private bool rewardedGetDoubleVideoClicked;
|
|
|
|
private bool rewardedVideoClicked;
|
|
|
|
private bool isBtnClicked;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public void UpdateRewardMultiplier(int rewardMultiplier)
|
|
{
|
|
if (rewardMultiplierText)
|
|
{
|
|
rewardMultiplierText.text = rewardMultiplier.ToString("F0");
|
|
}
|
|
rewardMultiplierCounter = rewardMultiplier;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
currentLevelNumberToShow = PersistableData.Instance.itemsData.currentLevelNumProgressive;
|
|
if (FirebaseInitialize.RemoteLevelOrder != null && FirebaseInitialize.RemoteLevelOrder.Count > 0)
|
|
{
|
|
currentLevel = FirebaseInitialize.RemoteLevelOrder[(currentLevelNumberToShow - 1) % FirebaseInitialize.RemoteLevelOrder.Count];
|
|
}
|
|
else
|
|
{
|
|
currentLevel++;
|
|
if (currentLevel > maxLevels)
|
|
{
|
|
currentLevel = Random.Range(1, maxLevels + 1);
|
|
}
|
|
}
|
|
Resources.UnloadUnusedAssets();
|
|
SpawnLevel(currentLevel);
|
|
if (FirebaseInitialize.AutoHintListLoaded && LevelScript.Instance != null)
|
|
{
|
|
LevelScript.Instance.isAutoHintLevel = FirebaseInitialize.AutoHintLevels.Contains(currentLevel);
|
|
}
|
|
if (currentLevelNumberToShow > maxLevels && currentLevel != 7 && currentLevel != 10)
|
|
{
|
|
Random.Range(0, 7);
|
|
}
|
|
if ((LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel) || (AppConstants.isRetryingLevel && PlayerPrefs.GetInt("HintWatched_" + currentLevelNumberToShow) == 1))
|
|
{
|
|
GameManager.Instance.ShowHintThroughCode();
|
|
}
|
|
bool flag = AppConstants.isRetryingAfterFail;
|
|
bool flag2 = LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel;
|
|
if (flag2 || !AppConstants.isRetryingAfterFail)
|
|
{
|
|
if (hintTutorialObj != null)
|
|
{
|
|
hintTutorialObj.SetActive(false);
|
|
}
|
|
}
|
|
else if (hintTutorialObj != null)
|
|
{
|
|
hintTutorialObj.SetActive(GameManager.FreeHintsRemaining);
|
|
}
|
|
AppConstants.isRetryingAfterFail = false;
|
|
if (PlayerPrefs.GetInt("EverFailed", 0) == 1)
|
|
{
|
|
UiManager.Instance.ShowFailButtons(flag2);
|
|
}
|
|
int num = PlayerPrefs.GetInt("HintWatched_" + currentLevelNumberToShow, 0);
|
|
int num2 = PlayerPrefs.GetInt("HintBtnUnlocked", 0);
|
|
if (num != 1 && !flag2 && num2 == 1)
|
|
{
|
|
GameManager.Instance.ShowHintButton(flag && !GameManager.FreeHintsRemaining);
|
|
}
|
|
LevelManager.instance.currentLevelCoinsEarned = 0;
|
|
if (AppConstants.shouldShowRemoveAdsOnStart)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = false;
|
|
AppConstants.removeAdsPanelFromLevelFlow = true;
|
|
Invoke("ShowRemoveAdsPanelFirstTime", 0.5f);
|
|
}
|
|
else if (!AdConstants.AdsRemoved && !AppConstants.isRetryingLevel && System.Array.IndexOf(AppConstants.RemoveAdsPanelLevels, currentLevelNumberToShow) >= 0 && AppConstants.lastIntAdShownLevel == currentLevelNumberToShow - 1)
|
|
{
|
|
Invoke("ShowRemoveAdsPanelFromList", 0.5f);
|
|
}
|
|
if (flag && !flag2 && num != 1 && !GameManager.FreeHintsRemaining && lastHintsPanelShownLevel != currentLevelNumberToShow && System.Array.IndexOf(AppConstants.HintsPanelLevels, currentLevelNumberToShow) >= 0)
|
|
{
|
|
lastHintsPanelShownLevel = currentLevelNumberToShow;
|
|
Invoke("ShowHintsPanelFromList", 0.5f);
|
|
}
|
|
}
|
|
|
|
private void ShowRemoveAdsPanelFromList()
|
|
{
|
|
UiManager.Instance.ShowRemoveAdPanelAtLevel();
|
|
}
|
|
|
|
private void ShowHintsPanelFromList()
|
|
{
|
|
UiManager.Instance.OpenHintsPanel();
|
|
}
|
|
|
|
private void ShowRemoveAdsPanelFirstTime()
|
|
{
|
|
UiManager.Instance.ShowRemoveAdPanelFromFlow();
|
|
}
|
|
|
|
private void SpawnLevel(int levelNumber)
|
|
{
|
|
if (levelNumber > maxLevels)
|
|
{
|
|
Debug.Log("All levels completed!");
|
|
return;
|
|
}
|
|
string levelName = levelPrefix + currentLevel;
|
|
GameObject gameObject = Resources.Load<GameObject>("Levels/" + levelName);
|
|
if (gameObject == null)
|
|
{
|
|
Debug.Log("Level prefab not found: " + levelName);
|
|
return;
|
|
}
|
|
if (currentLevelPrefab != null)
|
|
{
|
|
Destroy(currentLevelPrefab);
|
|
}
|
|
LevelAnalytics.Send(new string[1] { "Start" });
|
|
currentLevelPrefab = Instantiate(gameObject);
|
|
currentLevelPrefab.name = levelName;
|
|
}
|
|
|
|
private void LoadNextLevel()
|
|
{
|
|
if (FirebaseInitialize.RemoteLevelOrder != null && FirebaseInitialize.RemoteLevelOrder.Count > 0)
|
|
{
|
|
currentLevel = FirebaseInitialize.RemoteLevelOrder[PersistableData.Instance.itemsData.currentLevelNumProgressive % FirebaseInitialize.RemoteLevelOrder.Count];
|
|
}
|
|
else
|
|
{
|
|
currentLevel++;
|
|
if (currentLevel > maxLevels)
|
|
{
|
|
currentLevel = Random.Range(1, maxLevels + 1);
|
|
}
|
|
}
|
|
AppConstants.isRetryingAfterFail = false;
|
|
AppConstants.isRetryingLevel = false;
|
|
PlayerPrefs.DeleteKey("HintWatched_" + currentLevelNumberToShow);
|
|
PersistableData.Instance.IncreaseLevelNumber(currentLevel);
|
|
SoundManager.instance.StopSoundFxSource();
|
|
FadeSceneLoader.instance.LoadScene("Gameplay");
|
|
}
|
|
|
|
private void ResetClaimDoubleCoinsClickAgain()
|
|
{
|
|
rewardedGetDoubleVideoClicked = false;
|
|
}
|
|
|
|
private void DoubleRewardGranted()
|
|
{
|
|
UnityMainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
rewardedGetDoubleVideoClicked = false;
|
|
AppConstants.Haptic(HapticTypes.MediumImpact);
|
|
SoundManager.instance.PlaySFX_UI(SoundManager.instance.gameSoundSFX.buttonClickSfx, 1f);
|
|
if (isBtnClicked)
|
|
{
|
|
return;
|
|
}
|
|
isBtnClicked = true;
|
|
GameManager.OnCoinGrant((int)rewardMultiplierCounter, GetDoubleRewardCoinTr.position, delegate
|
|
{
|
|
Invoke("LoadNextLevel", 0.1f);
|
|
});
|
|
});
|
|
}
|
|
|
|
public void SkipLevelLvlFailed()
|
|
{
|
|
LevelAnalytics.Send(new string[2]
|
|
{
|
|
"Level_Fail_PT" + AdConstants.Is_PanelTest,
|
|
"Skip_Level"
|
|
});
|
|
|
|
SkipLevelGranted();
|
|
}
|
|
|
|
public void SkipLevelGameplay()
|
|
{
|
|
UiManager.Instance.SettingPanelAnim.SetBool("SettingIn", false);
|
|
UiManager.Instance.SettingPanelAnim.SetBool("SettingOut", true);
|
|
UiManager.Instance.isSettingsOpen = false;
|
|
LevelAnalytics.Send(new string[1] { "Skip_Level" });
|
|
|
|
SkipLevelGranted();
|
|
}
|
|
|
|
private void SkipLevelGranted()
|
|
{
|
|
if (isBtnClicked)
|
|
{
|
|
return;
|
|
}
|
|
isBtnClicked = true;
|
|
AppConstants.Haptic(HapticTypes.MediumImpact);
|
|
LoadNextLevel();
|
|
rewardedVideoClicked = false;
|
|
}
|
|
|
|
private void ResetSkipLevelClickAgain()
|
|
{
|
|
rewardedVideoClicked = false;
|
|
}
|
|
|
|
public void NoThanksGetDefaultCoins()
|
|
{
|
|
AppConstants.Haptic(HapticTypes.MediumImpact);
|
|
SoundManager.instance.PlaySFX_UI(SoundManager.instance.gameSoundSFX.buttonClickSfx, 1f);
|
|
if (isBtnClicked)
|
|
{
|
|
return;
|
|
}
|
|
isBtnClicked = true;
|
|
if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd())
|
|
{
|
|
if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
GameManager.Instance.ShowInterstitialTimer("Comp_Next", LoadNextLevel);
|
|
Invoke("LoadNextLevel", 1f);
|
|
return;
|
|
}
|
|
}
|
|
LoadNextLevel();
|
|
}
|
|
|
|
public void ReloadLevelGameplay()
|
|
{
|
|
SoundManager.instance.StopSoundFxSource();
|
|
SoundManager.instance.StopMusic();
|
|
GameManager.OnLevelReload?.Invoke();
|
|
AppConstants.isRetryingLevel = true;
|
|
LevelAnalytics.Send(new string[1] { "In_Game_Replay_Btn" });
|
|
ReloadLevel();
|
|
}
|
|
|
|
public void RetryLevelFailScreen()
|
|
{
|
|
AppConstants.isRetryingAfterFail = LevelScript.Instance == null || !LevelScript.Instance.isAutoHintLevel;
|
|
AppConstants.isRetryingLevel = true;
|
|
if (AdConstants.show_interstitial_on_fail && AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd())
|
|
{
|
|
if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
GameManager.Instance.ShowInterstitialTimer("Fail_Retry", ReloadLevel);
|
|
Invoke("ReloadLevel", 1f);
|
|
return;
|
|
}
|
|
}
|
|
ReloadLevel();
|
|
}
|
|
|
|
public void RetryLevelCompScreen()
|
|
{
|
|
AppConstants.isRetryingLevel = true;
|
|
AppConstants.isRetryingAfterFail = false;
|
|
LevelAnalytics.Send(new string[2]
|
|
{
|
|
"Level_Comp_PT" + AdConstants.Is_PanelTest,
|
|
"Try_Again"
|
|
});
|
|
if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd())
|
|
{
|
|
if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
GameManager.Instance.ShowInterstitialTimer("Comp_Retry", ReloadLevel);
|
|
Invoke("ReloadLevel", 1f);
|
|
return;
|
|
}
|
|
}
|
|
ReloadLevel();
|
|
}
|
|
|
|
private void ReloadLevel()
|
|
{
|
|
if (!AdConstants.AdsRemoved && (AdConstants.Is_PanelTest == 2 || AdConstants.Is_PanelTest == 3 || AdConstants.Is_PanelTest == 4))
|
|
{
|
|
|
|
AdsManager.HideMRec();
|
|
UiManager.Instance.BannerPati.SetActive(true);
|
|
}
|
|
AppConstants.Haptic(HapticTypes.MediumImpact);
|
|
SoundManager.instance.PlaySFX_UI(SoundManager.instance.gameSoundSFX.buttonClickSfx, 1f);
|
|
if (isBtnClicked)
|
|
{
|
|
return;
|
|
}
|
|
isBtnClicked = true;
|
|
SoundManager.instance.StopSoundFxSource();
|
|
FadeSceneLoader.instance.LoadScene("Gameplay");
|
|
}
|
|
|
|
public void ReloadLevelSilently()
|
|
{
|
|
if (isBtnClicked)
|
|
{
|
|
return;
|
|
}
|
|
isBtnClicked = true;
|
|
AppConstants.isRetryingAfterFail = LevelScript.Instance == null || !LevelScript.Instance.isAutoHintLevel;
|
|
AppConstants.isRetryingLevel = true;
|
|
if (!AdConstants.AdsRemoved)
|
|
{
|
|
|
|
AdsManager.HideMRec();
|
|
UiManager.Instance.BannerPati.SetActive(true);
|
|
}
|
|
FadeSceneLoader.instance.LoadScene("Gameplay");
|
|
}
|
|
|
|
public void SetupFailScreenNoPanelTest()
|
|
{
|
|
if (skipBtn_Fail != null)
|
|
{
|
|
skipBtn_Fail.SetActive(false);
|
|
}
|
|
if (retryBtn_Fail != null)
|
|
{
|
|
retryBtn_Fail.SetActive(false);
|
|
}
|
|
if (UiManager.Instance.reloadBtnRect != null)
|
|
{
|
|
UiManager.Instance.reloadBtnRect.gameObject.SetActive(false);
|
|
}
|
|
Invoke("AutoRetryAfterFail_NoPanel", 1.5f);
|
|
}
|
|
|
|
private void AutoRetryAfterFail_NoPanel()
|
|
{
|
|
if (!AdConstants.AdsRemoved)
|
|
{
|
|
|
|
AdsManager.HideMRec();
|
|
AdsManager.ShowBanner();
|
|
}
|
|
bool flag = LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel;
|
|
AppConstants.isRetryingAfterFail = !flag;
|
|
AppConstants.isRetryingLevel = true;
|
|
LevelAnalytics.Send(new string[2]
|
|
{
|
|
"Level_Fail_PT" + AdConstants.Is_PanelTest,
|
|
"Auto_Retry"
|
|
});
|
|
if (AdConstants.show_interstitial_on_fail && AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd())
|
|
{
|
|
if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
UiManager.Instance.LevelFailedPanel.gameObject.SetActive(false);
|
|
SoundManager.instance.StopSoundFxSource();
|
|
GameManager.Instance.ShowInterstitialTimer("Fail_AutoRetry_NoPanel", null);
|
|
}
|
|
}
|
|
if (!AdConstants.AdsRemoved)
|
|
{
|
|
|
|
AdsManager.HideMRec();
|
|
AdsManager.ShowBanner();
|
|
}
|
|
ReloadLevel();
|
|
}
|
|
|
|
public void SetupCompScreenConfettiTest()
|
|
{
|
|
if (UiManager.Instance.reloadBtnRect != null)
|
|
{
|
|
UiManager.Instance.reloadBtnRect.gameObject.SetActive(false);
|
|
}
|
|
Invoke("AutoNextAfterComp_ConfettiTest", 1.5f);
|
|
}
|
|
|
|
private void AutoNextAfterComp_ConfettiTest()
|
|
{
|
|
LevelAnalytics.Send(new string[2]
|
|
{
|
|
"Level_Comp_PT" + AdConstants.Is_PanelTest,
|
|
"Confetti_AutoContinue"
|
|
});
|
|
if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd())
|
|
{
|
|
if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
if (GameManager.Instance.confettiOnWin != null)
|
|
{
|
|
GameManager.Instance.confettiOnWin.SetActive(false);
|
|
}
|
|
SoundManager.instance.StopSoundFxSource();
|
|
GameManager.Instance.ShowInterstitialTimer("Comp_Confetti_AutoNext", null);
|
|
}
|
|
}
|
|
LoadNextLevel();
|
|
}
|
|
|
|
public void SetupCompScreenNoPanelTest()
|
|
{
|
|
if (noThanksBtn_Comp != null)
|
|
{
|
|
noThanksBtn_Comp.SetActive(false);
|
|
}
|
|
if (retryBtn_Comp != null)
|
|
{
|
|
retryBtn_Comp.SetActive(false);
|
|
}
|
|
if (UiManager.Instance.reloadBtnRect != null)
|
|
{
|
|
UiManager.Instance.reloadBtnRect.gameObject.SetActive(false);
|
|
}
|
|
Invoke("AutoNextAfterComp_NoPanel", 1.5f);
|
|
}
|
|
|
|
private void AutoNextAfterComp_NoPanel()
|
|
{
|
|
LevelAnalytics.Send(new string[2]
|
|
{
|
|
"Level_Comp_PT" + AdConstants.Is_PanelTest,
|
|
"NoPanel_AutoContinue"
|
|
});
|
|
if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd())
|
|
{
|
|
if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0)
|
|
{
|
|
AppConstants.shouldShowRemoveAdsOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
UiManager.Instance.LevelCompletePanel.gameObject.SetActive(false);
|
|
SoundManager.instance.StopSoundFxSource();
|
|
GameManager.Instance.ShowInterstitialTimer("Comp_AutoNext_NoPanel", null);
|
|
}
|
|
}
|
|
if (!AdConstants.AdsRemoved)
|
|
{
|
|
|
|
AdsManager.HideMRec();
|
|
AdsManager.ShowBanner();
|
|
}
|
|
LoadNextLevel();
|
|
}
|
|
}
|