195 lines
6.6 KiB
C#
195 lines
6.6 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-05-18
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "MainSceneLogic" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 主场景逻辑
|
|||
|
/// </summary>
|
|||
|
public class MainSceneLogic : SceneLogic
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
static bool _IsFirst = true;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
private void UnloadUnusedAssets()
|
|||
|
{
|
|||
|
Resources.UnloadUnusedAssets();
|
|||
|
System.GC.Collect();
|
|||
|
}
|
|||
|
|
|||
|
private void ProcessCharge()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
Dictionary<string, object> _userDict;
|
|||
|
private void ReportUserData()
|
|||
|
{
|
|||
|
if (_userDict == null)
|
|||
|
_userDict = new Dictionary<string, object>(8);
|
|||
|
else
|
|||
|
_userDict.Clear();
|
|||
|
|
|||
|
var dict = _userDict;
|
|||
|
dict.Add("combat_value", PlayerProxy.Instance.combatValue);
|
|||
|
dict.Add("coin", MoneyProxy.Instance.coin);
|
|||
|
dict.Add("gem", MoneyProxy.Instance.gem);
|
|||
|
dict.Add("js", MoneyProxy.Instance.chip);
|
|||
|
dict.Add("yt", MoneyProxy.Instance.stone);
|
|||
|
dict.Add("vip", VipProxy.Instance.curVip);
|
|||
|
dict.Add("no_ad", RmbShopProxy.Instance.IsRemoveAd());
|
|||
|
dict.Add("level", LevelProxy.Instance.currentCompletedLevel);
|
|||
|
|
|||
|
KStatistics.Instance.SetUserData(dict);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Time.timeScale = 1f;
|
|||
|
#if !UNITY_EDITOR && !UNITY_WEBGL
|
|||
|
UnityEngine.Scripting.GarbageCollector.GCMode = UnityEngine.Scripting.GarbageCollector.Mode.Enabled;
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator Start()
|
|||
|
{
|
|||
|
KUIWindow.CloseWindow<UI.VersionNoteBox>();
|
|||
|
|
|||
|
int isOnline = int.MaxValue;
|
|||
|
do
|
|||
|
{
|
|||
|
if (isOnline > 0)
|
|||
|
{
|
|||
|
isOnline = -1;
|
|||
|
AntiCheatProxy.Instance.CheckCheat((error, message) =>
|
|||
|
{
|
|||
|
isOnline = error;
|
|||
|
if (error != 0)
|
|||
|
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, message);
|
|||
|
});
|
|||
|
}
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
while (isOnline != 0);
|
|||
|
|
|||
|
yield return null;
|
|||
|
LevelProxy.Instance.EndlessSettle();
|
|||
|
yield return null;
|
|||
|
RmbShopProxy.Instance.CheckSpecialReward();
|
|||
|
yield return null;
|
|||
|
MailProxy.Instance.GetMails(null);
|
|||
|
yield return null;
|
|||
|
RankingProxy.Instance.UploadAllRanking();
|
|||
|
yield return null;
|
|||
|
var dict = new Dictionary<string, string>();
|
|||
|
//dict.Add("battle", $"{{\"wxgame\":{{\"score\":{PlayerProxy.Instance.combatValue},\"update_time\":{Launch.Timestamp}}}}}");
|
|||
|
//dict.Add("level", $"{{\"wxgame\":{{\"score\":{LevelProxy.Instance.currentCompletedLevel},\"update_time\":{Launch.Timestamp}}}}}");
|
|||
|
dict.Add("battle", PlayerProxy.Instance.combatValue.ToString());
|
|||
|
dict.Add("level", LevelProxy.Instance.currentCompletedLevel.ToString());
|
|||
|
|
|||
|
KPlatform.Instance.SetUserCloundStorage(dict, (error, message) =>
|
|||
|
{
|
|||
|
Debug.Log("SetUserCloundStorage " + message);
|
|||
|
});
|
|||
|
|
|||
|
//
|
|||
|
if (_IsFirst)
|
|||
|
{
|
|||
|
//UI.VersionGuideBox.Show();
|
|||
|
|
|||
|
//版本奖励
|
|||
|
if (System.Version.TryParse(Application.version, out var currVersion))
|
|||
|
{
|
|||
|
System.Version.TryParse(ArchiveProxy.Instance.GetString("app_ver"), out var saveVersion);
|
|||
|
if (saveVersion == null || currVersion > saveVersion)
|
|||
|
{
|
|||
|
ArchiveProxy.Instance.SetString("app_ver", Application.version);
|
|||
|
if (!GlobalVar.IsNewPlayer)
|
|||
|
MailProxy.Instance.PostLocalMail(1000);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//离线奖励
|
|||
|
bool offlineState = false;
|
|||
|
int offlineTimestamp = ArchiveProxy.Instance.GetInt(GlobalDefine.KEY_OFFLINE_TIMESTAMP);
|
|||
|
if (offlineTimestamp <= 0)
|
|||
|
{
|
|||
|
ArchiveProxy.Instance.SetInt(GlobalDefine.KEY_OFFLINE_TIMESTAMP, Launch.Timestamp);
|
|||
|
}
|
|||
|
else/* if (TimeProxy.Instance.GetTimeKey(TimeProxy.每日离线奖励))*/
|
|||
|
{
|
|||
|
int offlineSeconds = Mathf.Clamp(Launch.Timestamp - offlineTimestamp, 0, 86400);
|
|||
|
|
|||
|
var energyOverflow = Mathf.RoundToInt(offlineSeconds / 7200f);
|
|||
|
if (energyOverflow > 0)
|
|||
|
{
|
|||
|
offlineState = true;
|
|||
|
LevelProxy.Instance.OfflineLevel(energyOverflow, (error, message) =>
|
|||
|
{
|
|||
|
offlineState = false;
|
|||
|
});
|
|||
|
ArchiveProxy.Instance.SetInt(GlobalDefine.KEY_OFFLINE_TIMESTAMP, Launch.Timestamp);
|
|||
|
//TimeProxy.Instance.TryTimeKey(TimeProxy.每日离线奖励);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
while (offlineState)
|
|||
|
yield return null;
|
|||
|
|
|||
|
LevelProxy.Instance.LoadPlayingLevelState();
|
|||
|
}
|
|||
|
|
|||
|
_IsFirst = false;
|
|||
|
|
|||
|
yield return null;
|
|||
|
UnloadUnusedAssets();
|
|||
|
|
|||
|
ReportUserData();
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
UnloadUnusedAssets();
|
|||
|
}
|
|||
|
|
|||
|
private float _lastUpdateTime;
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (Time.time - _lastUpdateTime > 100f)
|
|||
|
{
|
|||
|
_lastUpdateTime = Time.time;
|
|||
|
|
|||
|
var levelProxy = LevelProxy.Instance;
|
|||
|
if (levelProxy != null)
|
|||
|
{
|
|||
|
//KStatistics.Instance.ReportEvent_Fps("main_window", levelProxy.maxUnlockChapter, levelProxy.maxUnlockLevel, 0, KGMTools.Instance.fps, "", SystemInfo.processorType, SystemInfo.graphicsDeviceName, Screen.currentResolution.ToString(), SystemInfo.systemMemorySize, 0, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|