GameApplctionMono.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using Excel2Json;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace GameUI
  8. {
  9. public class GameApplctionMono : MonoBehaviour
  10. {
  11. public GameApplction GameApplction;
  12. public void Update()
  13. {
  14. #if UNITY_EDITOR
  15. // if (EditorApplication.isPaused)
  16. // {
  17. // return;
  18. // }
  19. #endif
  20. EventSystem.Instance.Update();
  21. AssetBundleLoadManager.Instance.UpdateBundle();
  22. TimeHelper.clientFrame = TimeHelper.ClientFrame() + (long)(Time.deltaTime * 1000);
  23. }
  24. private class TestHERO
  25. {
  26. public int level;
  27. public int exp;
  28. public void AddExp(int e)
  29. {
  30. this.exp += e;
  31. HeroPowerUpConfig allPowerUp = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  32. while (exp > allPowerUp.levelUpExp && allPowerUp.levelUpExp > 0)
  33. {
  34. exp = exp - allPowerUp.levelUpExp;
  35. level++;
  36. allPowerUp = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  37. }
  38. }
  39. }
  40. // [ContextMenu("monster")]
  41. // public void Test()
  42. // {
  43. // LevelBattleConfig[] levelBattleConfigs = ConfigComponent.Instance.GetAll<LevelBattleConfig>();
  44. // TestHERO testHero = new TestHERO();
  45. // testHero.level = 1;
  46. // string m = "";
  47. // for (int i = 0; i < levelBattleConfigs.Length; i++)
  48. // {
  49. // LevelBattleConfig levelBattleConfig = levelBattleConfigs[i];
  50. // int jy = levelBattleConfig.exp * levelBattleConfig.miniExpAndGold[0] / 4;
  51. // testHero.AddExp(jy);
  52. // m += testHero.level + "\n";
  53. // }
  54. // Debug.Log(m);
  55. // }
  56. private void OnApplicationFocus(bool hasFocus)
  57. {
  58. if (!hasFocus)
  59. {
  60. GameApplction?.OnApplicationQuit();
  61. }
  62. if (!TimeHelper.IsNetworkTimeReady)
  63. {
  64. LogTool.Error("没有获取到网络时间,不记录挂机时间!");
  65. return;
  66. }
  67. if (!hasFocus && PlayerManager.Instance.isLogin)
  68. {
  69. // 退出时记录时间
  70. AccountFileInfo.Instance.playerData.ExitTime = TimeHelper.ClientNow();
  71. AccountFileInfo.Instance.SavePlayerData();
  72. }
  73. else if (PlayerManager.Instance.isLogin)
  74. {
  75. PlayerManager.Instance.CalculateOfflineRewards();
  76. }
  77. }
  78. private void OnApplicationQuit()
  79. {
  80. GameApplction?.OnApplicationQuit();
  81. if (!TimeHelper.IsNetworkTimeReady)
  82. {
  83. return;
  84. }
  85. // 退出时记录时间
  86. AccountFileInfo.Instance.playerData.ExitTime = TimeHelper.ClientNow();
  87. AccountFileInfo.Instance.SavePlayerData();
  88. // if (hasFocus)
  89. // {
  90. //
  91. // }
  92. // else
  93. // {
  94. // PlayerManager.Instance.CalculateOfflineRewards();
  95. // }
  96. }
  97. // private void OnApplicationPause(bool pauseStatus)
  98. // {
  99. // throw new NotImplementedException();
  100. // }
  101. // public async void OnApplicationPause(bool pauseStatus)
  102. // {
  103. // }
  104. public void LateUpdate()
  105. {
  106. EventSystem.Instance.LateUpdate();
  107. }
  108. }
  109. }