120 lines
2.7 KiB
C#
120 lines
2.7 KiB
C#
using CaoCao;
|
||
using CaoCao.Runtime;
|
||
using System;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
|
||
namespace Game
|
||
{
|
||
/// <summary>
|
||
/// 游戏入口。
|
||
/// </summary>
|
||
public partial class AppEntry : MonoBehaviour
|
||
{
|
||
//public static List<ServerData> GameServerList = new List<ServerData>();
|
||
public static int LastLoginServerId = 0;
|
||
|
||
public static BuiltinDataComponent BuiltinData
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
public static ResourcesComponent Resources
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
public static UIComponent UI
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
public static MainPlayerComponent MainPlayer
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
public static long Ticktime
|
||
{
|
||
get
|
||
{
|
||
return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
|
||
}
|
||
}
|
||
|
||
public static GameObject confirmUIGo = null;
|
||
public static GameObject updateUIGo = null;
|
||
|
||
//gc释放时间
|
||
long _GcTime;
|
||
|
||
public long GCTime
|
||
{
|
||
get { return _GcTime; }
|
||
set { _GcTime = value; }
|
||
}
|
||
|
||
//gc释放时间
|
||
long _idleTime;
|
||
public long IdleTime
|
||
{
|
||
get { return _idleTime; }
|
||
set { _idleTime = value; }
|
||
}
|
||
|
||
private static void InitCustomComponents()
|
||
{
|
||
BuiltinData = GameEntry.GetComponent<BuiltinDataComponent>();
|
||
Resources = GameEntry.GetComponent<ResourcesComponent>();
|
||
MainPlayer = GameEntry.GetComponent<MainPlayerComponent>();
|
||
UI = GameEntry.GetComponent<UIComponent>();
|
||
}
|
||
|
||
public static void QuitGame()
|
||
{
|
||
#if UNITY_EDITOR
|
||
UnityEditor.EditorApplication.isPlaying = false;
|
||
#else
|
||
Application.Quit();
|
||
#endif
|
||
}
|
||
|
||
//非随机调用策略
|
||
void CheckTickTime()
|
||
{
|
||
long tickTime = Ticktime - _GcTime;
|
||
if (tickTime > 60000)
|
||
{
|
||
UnityEngine.Resources.UnloadUnusedAssets();
|
||
GC.Collect();
|
||
_GcTime = Ticktime;
|
||
IdleTime = Ticktime;
|
||
}
|
||
}
|
||
|
||
//待机状态策略
|
||
void CheckIdleTime()
|
||
{
|
||
//待机超过2分钟,调用gc
|
||
if (Ticktime - IdleTime > 60 * 60 * 1000)
|
||
{
|
||
Log.Info("待机超过2分钟,手动调用GC");
|
||
IdleTime = Ticktime;
|
||
GCTime = Ticktime;
|
||
|
||
UnityEngine.Resources.UnloadUnusedAssets();
|
||
GC.Collect();
|
||
}
|
||
}
|
||
|
||
|
||
public void LateUpdate()
|
||
{
|
||
CheckIdleTime();
|
||
}
|
||
}
|
||
} |