2022-05-23 13:39:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
|
|
|
|
public class GameManager : D_MonoSingleton<GameManager>
|
|
|
|
|
|
{
|
2022-07-04 11:17:39 +00:00
|
|
|
|
#region for debug
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public BlockManager CurrentPlayerBlockMgr;
|
|
|
|
|
|
public BlockManager CurrentEnemyBlockMgr;
|
2022-07-04 11:17:39 +00:00
|
|
|
|
public GroupManager PlayerGroupMgr;
|
|
|
|
|
|
public GroupManager EnemyGroupMgr;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public Camera CurrentGameCam;
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
public bool IsPlayerUndefeatable = false;
|
|
|
|
|
|
public bool IsEnemyUndefeatable = false;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public int GameSpeed
|
|
|
|
|
|
{
|
|
|
|
|
|
get => mGameSpeed;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mGameSpeed = value;
|
|
|
|
|
|
Utils.SetGameSpeed(mGameSpeed);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private int mGameSpeed = 1;
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if USE_IAP
|
2022-07-04 11:17:39 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseBegin += OnPurchaseBegin;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseDone += OnPurchaseResult;
|
|
|
|
|
|
IAPTool.Instance.OnRestoreDone += OnRestoreResult;
|
|
|
|
|
|
#endif
|
2022-07-04 11:17:39 +00:00
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
MMOModule.Instance.OnDataOverride += DataOverride;
|
2022-07-04 11:17:39 +00:00
|
|
|
|
MMOModule.Instance.OnDiamondUpdate += UpdateDiamond;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
|
|
|
|
|
|
MMOModule.Instance.OnShowRV += ShowRV;
|
|
|
|
|
|
MMOModule.Instance.OnShowIV += ShowIV;
|
|
|
|
|
|
MMOModule.Instance.OnLogEvent += LogRobuxEvent;
|
|
|
|
|
|
MMOModule.Instance.OnGetConfig += GetConfig;
|
|
|
|
|
|
MMOModule.Instance.OnShare += TKGSDKManager.Instance.Share;
|
2022-07-04 11:17:39 +00:00
|
|
|
|
MMOModule.Instance.OnOpenMoreGames += TKGSDKManager.Instance.OpenMoreGame;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if USE_IAP
|
2022-07-04 11:17:39 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseBegin -= OnPurchaseBegin;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult;
|
|
|
|
|
|
IAPTool.Instance.OnRestoreDone -= OnRestoreResult;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
#region MMO
|
|
|
|
|
|
private void DataOverride()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool tIsMMO = PlayerData.Instance.IsMMOUser;
|
2022-10-10 08:11:41 +00:00
|
|
|
|
bool tIsIP = PlayerData.Instance.IsIPShow;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
PlayerData.Load();
|
|
|
|
|
|
SettingData.Load();
|
|
|
|
|
|
PlayerData.Instance.IsMMOUser = tIsMMO;
|
2022-10-10 08:11:41 +00:00
|
|
|
|
PlayerData.Instance.IsIPShow = tIsIP;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
private void UpdateDiamond(int pDiamond)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerData.Instance.Diamond = pDiamond;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
UIManager.Instance.GetUI<PanelTopBar>().RefreshDiamond();
|
2022-07-04 11:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
private void ShowRV(string pPos, Action<bool> pDelResult)
|
2022-07-04 11:17:39 +00:00
|
|
|
|
{
|
2022-09-09 14:35:49 +00:00
|
|
|
|
AdsUtils.PlayReward((TKGRVPositionName)Enum.Parse(typeof(TKGRVPositionName), pPos), pDelResult);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowIV(string pPos)
|
|
|
|
|
|
{
|
|
|
|
|
|
AdsUtils.PlayInterstitial((TKGIVAdPositionName)Enum.Parse(typeof(TKGIVAdPositionName), pPos));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetConfig(string pKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
return TKGSDKManager.Instance.GetConfigStr((TKGParamKey)Enum.Parse(typeof(TKGParamKey), pKey));
|
2022-07-04 11:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LogRobuxEvent(string pEvent, string pKey, string pValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
TKGSDKManager.Instance.LogEvent(pEvent, pKey, pValue);
|
|
|
|
|
|
}
|
2022-09-09 14:35:49 +00:00
|
|
|
|
#endregion
|
2022-07-04 11:17:39 +00:00
|
|
|
|
|
|
|
|
|
|
private void OnPurchaseBegin()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if USE_IAP
|
|
|
|
|
|
UIManager.Instance.OpenUI<PanelLoading>();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
private void OnPurchaseResult(string pID, bool pResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if USE_IAP
|
|
|
|
|
|
if (pID.Equals(IAPProducts.NoAds))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerData.Instance.IsNoAds = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
UIUtils.ShowTips(LanguageConfig.Instance.GetText(pResult ? "BuyNoAdsSucceed" : "BuyNoAdsFail"));
|
|
|
|
|
|
}
|
2022-07-04 11:17:39 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!UIManager.Instance.GetUI<PanelShop>().IsOpened)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataIAP tData = TableIAP.Instance.GetData(pID);
|
|
|
|
|
|
if (tData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerData.Instance.Diamond += tData.DiamondNum;
|
|
|
|
|
|
UIManager.Instance.GetUI<PanelTopBar>().PopDiamond(tData.DiamondNum);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
UIManager.Instance.CloseUI<PanelLoading>();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnRestoreResult(bool pResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIUtils.ShowTips(LanguageConfig.Instance.GetText(pResult ? "RestoreSucceed" : "RestoreFail"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void LoadGame()
|
|
|
|
|
|
{
|
|
|
|
|
|
GameSpeed = 1;
|
|
|
|
|
|
TimerManager.Instance.ClearAll();
|
|
|
|
|
|
SceneManager.LoadScene("Game");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|