167 lines
4.3 KiB
C#
167 lines
4.3 KiB
C#
|
using Axibug;
|
|||
|
using Axibug.Runtime;
|
|||
|
using System;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.Events;
|
|||
|
|
|||
|
namespace Game
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20><>Ϸ<EFBFBD><CFB7><EFBFBD>ڡ<EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public partial class AppEntry : MonoBehaviour
|
|||
|
{
|
|||
|
public static BuiltinDataComponent BuiltinData
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
}
|
|||
|
|
|||
|
public static UpdateComponent HotUpdate
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
}
|
|||
|
|
|||
|
//public static UIMgr UI
|
|||
|
//{
|
|||
|
// get;
|
|||
|
// private set;
|
|||
|
//}
|
|||
|
|
|||
|
//public static Tips Tips
|
|||
|
//{
|
|||
|
// get;
|
|||
|
// private set;
|
|||
|
//}
|
|||
|
|
|||
|
public static LocalStorage LocalStorage
|
|||
|
{
|
|||
|
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<67>ͷ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
long _GcTime;
|
|||
|
|
|||
|
public long GCTime
|
|||
|
{
|
|||
|
get { return _GcTime; }
|
|||
|
set { _GcTime = value; }
|
|||
|
}
|
|||
|
|
|||
|
//gc<67>ͷ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
long _idleTime;
|
|||
|
public long IdleTime
|
|||
|
{
|
|||
|
get { return _idleTime; }
|
|||
|
set { _idleTime = value; }
|
|||
|
}
|
|||
|
|
|||
|
private static void InitCustomComponents()
|
|||
|
{
|
|||
|
BuiltinData = GameEntry.GetComponent<BuiltinDataComponent>();
|
|||
|
HotUpdate = GameEntry.GetComponent<UpdateComponent>();
|
|||
|
//UI = GameEntry.GetComponent<UIMgr>();
|
|||
|
//Tips = GameEntry.GetComponent<Tips>();
|
|||
|
LocalStorage = LocalStorage.Instance;
|
|||
|
}
|
|||
|
|
|||
|
public static void QuitGame()
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
UnityEditor.EditorApplication.isPlaying = false;
|
|||
|
#else
|
|||
|
Application.Quit();
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
|
|||
|
void CheckTickTime()
|
|||
|
{
|
|||
|
long tickTime = Ticktime - _GcTime;
|
|||
|
if (tickTime > 60000)
|
|||
|
{
|
|||
|
UnityEngine.Resources.UnloadUnusedAssets();
|
|||
|
GC.Collect();
|
|||
|
_GcTime = Ticktime;
|
|||
|
IdleTime = Ticktime;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|||
|
void CheckIdleTime()
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>gc
|
|||
|
if (Ticktime - IdleTime > 120000)
|
|||
|
{
|
|||
|
Log.Info("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD>ӣ<EFBFBD><D3A3>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>GC");
|
|||
|
IdleTime = Ticktime;
|
|||
|
GCTime = Ticktime;
|
|||
|
|
|||
|
UnityEngine.Resources.UnloadUnusedAssets();
|
|||
|
GC.Collect();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static T OpenNativeUI<T>(string name) where T : UnityEngine.Object
|
|||
|
{
|
|||
|
string path = $"Prefabs/{name}";
|
|||
|
UnityEngine.Object obj = Resources.Load(path);
|
|||
|
GameObject go = Instantiate(obj) as GameObject;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ǶԻ<C7B6><D4BB><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>update<74><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (name.Equals("NativeConfirmUI"))
|
|||
|
{
|
|||
|
confirmUIGo = go;
|
|||
|
go.transform.SetParent(updateUIGo.transform, false);
|
|||
|
}
|
|||
|
else if (name.Equals("NativeUpdateUI"))
|
|||
|
updateUIGo = go;
|
|||
|
|
|||
|
return go.GetComponent<T>();
|
|||
|
}
|
|||
|
|
|||
|
public static void CloseNativeUI(string name)
|
|||
|
{
|
|||
|
if (name.Equals("NativeConfirmUI"))
|
|||
|
{
|
|||
|
DestroyImmediate(confirmUIGo);
|
|||
|
confirmUIGo = null;
|
|||
|
}
|
|||
|
else if (name.Equals("NativeUpdateUI"))
|
|||
|
{
|
|||
|
DestroyImmediate(updateUIGo);
|
|||
|
updateUIGo = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static NativeConfirmUI ShowMessageBox(string title, string context, string confirmText, string cancelText, UnityAction confirmAction, UnityAction cancelAction)
|
|||
|
{
|
|||
|
NativeConfirmUI confirmUI = OpenNativeUI<NativeConfirmUI>("NativeConfirmUI");
|
|||
|
if (confirmUI == null)
|
|||
|
throw new GameException("ԭ<><D4AD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>");
|
|||
|
|
|||
|
confirmUI.Show(title, context, confirmText, cancelText);
|
|||
|
confirmUI.AddOnclickListener(confirmAction, cancelAction);
|
|||
|
|
|||
|
return confirmUI;
|
|||
|
}
|
|||
|
|
|||
|
public void LateUpdate()
|
|||
|
{
|
|||
|
CheckIdleTime();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|