Files
taptap2024_GJ_chidouren/Assets/Scripts/System/GameManager.cs

167 lines
5.0 KiB
C#
Raw Normal View History

2024-10-16 00:03:41 +08:00
using System.AchieveSystem;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.OfflineSystem;
using System.RandomPool;
using System.ScriptListener;
using System.StateSystem;
using Framework.Audio;
using Framework.Save;
using Framework.Timer;
using Framework.Utils.Extend;
using Framework.Utils.SingletonTemplate;
using Game;
using Script.Core.Utils.Extend;
using Script.Core.Utils.Vibration;
using StateSystem;
// using TapTap.Connect;
// using TapSDK.UI;
using UnityEngine;
using UnityEngine.Networking;
using Views;
using UIManager = Framework.UI.UIManager;
namespace System
{
public class GameManager : MgrMonoBase<GameManager>
{
public string AssetPath { get; private set; }
private SystemScript _script;
public long CurrentTime { get; private set; }
public bool HasCheckOffline;
protected override void InitMgr ()
{
// this.AssetPath = Assets.AssetRoot;
// Assets.updatePath = this.AssetPath;
this._script = new SystemScript ();
}
public void StartAutoSave ()
{
GameUpdateMgr.Instance.AddUpdater (UpdateLogic);
}
public void EndAutoSave ()
{
GameUpdateMgr.Instance.RemoveUpdater (UpdateLogic);
}
private const int AutoSaveUnit = 30;
private float curTimeUnit = 0;
private void UpdateLogic ()
{
//自动存档
this.curTimeUnit += Time.deltaTime;
if (this.curTimeUnit >= AutoSaveUnit)
{
this.curTimeUnit = 0;
Account.Instance.Save (SaveData.Game);
OfflineMgr.Instance.UpdateHistoryTime ();
}
}
public void ScriptRegist ()
{
this._script.Active ();
}
public void Inited ()
{
this.HasCheckOffline = false;
// this.StickerRandomUtil = new WeightRandomPool ();
// foreach (var rofStickerRow in RofManagerConfig.Instance.RofStickerTable.GetAllRow ())
// {
// this.StickerRandomUtil.PutNode (rofStickerRow.ID , rofStickerRow.Weight);
// }
}
public void Vibrator (VibratorScale vibratorScale)
{
#if UNITY_EDITOR
return;
#endif
var shakeValue = Account.Instance.AccountSystemData.ShakeValue;
2024-10-22 19:10:15 +08:00
var duration = 250;
2024-10-16 00:03:41 +08:00
int type = (int)vibratorScale;
if (VibratorImp.Instance.HasCustomVibration ())
{
VibratorImp.Instance.Vibrator_Effect (type , shakeValue);
}
else
{
VibratorImp.Instance.Vibrator_Normal (duration * shakeValue, type * 20);
}
}
public void OnAdMask (bool isOpen)
{
if (isOpen)
{
UIManager.Instance.OpenView (UIPanel.MaskPanel, true);
}
else
{
UIManager.Instance.CloseView (UIPanel.MaskPanel);
}
}
public void ExitGame ()
{
GameStateManager.Instance.OpenState (GameGlobalState.GameExit);
}
public void InitSystemTime (Action callback)
{
OfflineTimeLoader loader = new OfflineTimeLoader ();
loader.LoadTime (curTime =>
{
this.CurrentTime = curTime == 0 ? DateTime.Now.ToTimeStamp13 () : curTime;
var dateTime13 = this.CurrentTime.GetDateTime13 ();
//将CurrentTime精度精确到天抛弃掉小时和分钟
this.CurrentTime = new DateTime (dateTime13.Year, dateTime13.Month, dateTime13.Day).ToTimeStamp13 ();
OfflineMgr.Instance.InitStartTime (null , curTime);
UpdateOfflineTime ();
callback?.Invoke ();
});
}
private void UpdateOfflineTime ()
{
var offlineTimeSpan = OfflineMgr.Instance.OfflineTimeSpan; //获取离线时长
Account.Instance.AccountSystemData.UpdateCurrentTime (this.CurrentTime);
Account.Instance.AccountGameData.UpdateCurrentTime (this.CurrentTime);
Account.Instance.OfflineControl (offlineTimeSpan);
}
public void OnGlobalVideoAdComplete (bool isComplete)
{
if (isComplete)
{
// AudioManager.Instance.PlaySoundEffect (SeAudio.AD_Complete);
AchievementMgr.Instance.Push (AchievementCode.WatchAd);
}
}
private void OnApplicationFocus (bool hasFocus)
{
}
public void OpenAppShop ()
{
UIManager.Instance.OpenTip ("评价反馈", "你的评价是我们前进的最大动力,无论赞美还是诚恳的建议,亦或者一个点赞!",
() =>
{
LaunchAppUtils.ToTapTapTargetApp (GameGlobalConfig.Instance.TapAppUrl);
}, () => { });
}
}
}