104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace BallKingdomCrush
|
|
{
|
|
public class SApplication : MonoBehaviour
|
|
{
|
|
public static bool IsAppQuit { get; private set; }
|
|
|
|
public bool IsRestart { get; private set; }
|
|
public int RestartCount { get; private set; }
|
|
public bool IsAppFocus { get; private set; }
|
|
public bool IsAppPause { get; private set; }
|
|
public long LastFocusFlaseTime { get; private set; }
|
|
|
|
public virtual void Init()
|
|
{
|
|
IsAppFocus = true;
|
|
}
|
|
|
|
public virtual void Enable()
|
|
{
|
|
CreateEnvironment();
|
|
}
|
|
|
|
private void CreateEnvironment()
|
|
{
|
|
AppObjConst.ApplicationGo = gameObject;
|
|
AppObjConst.EngineSingletonGo = new GameObject(AppObjConst.EngineSingletonGoName);
|
|
AppObjConst.EngineSingletonGo.SetParent(AppObjConst.FrameGo);
|
|
}
|
|
|
|
private void CloseApp()
|
|
{
|
|
if (UIManager.Instance != null)
|
|
{
|
|
UIManager.Instance.DisposeAllUI();
|
|
}
|
|
|
|
ModuleManager.Instance.DisposeAllModule();
|
|
ManagerOfManager.Instance.DisposeAllManager();
|
|
ManagerOfManager.Instance.Dispose();
|
|
}
|
|
|
|
private void OnApplicationFocus(bool focus)
|
|
{
|
|
IsAppFocus = focus;
|
|
if (focus)
|
|
{
|
|
// MainThreadDispatcher.Instance.Dispatch(MainThreadMsg.App_Focus_True, focus);
|
|
AppDispatcher.Instance.Dispatch(MainThreadMsg.App_Focus_True, focus);
|
|
Debug.Log(focus);
|
|
}
|
|
else
|
|
{
|
|
AppDispatcher.Instance.Dispatch(MainThreadMsg.App_Pause_False, focus);
|
|
SaveData.SaveDataFunc();
|
|
LastFocusFlaseTime = DateTimeManager.Instance.GetServerCurrTimestamp();
|
|
}
|
|
}
|
|
|
|
private void OnApplicationPause(bool pause)
|
|
{
|
|
Debug.Log("pause========");
|
|
IsAppPause = pause;
|
|
#if !UNITY_EDITOR
|
|
if (pause)//进入后台
|
|
{
|
|
AppDispatcher.Instance.Dispatch(AppMsg.App_Pause_True, pause);
|
|
AppDispatcher.Instance.Dispatch(MainThreadMsg.App_Focus_True, pause);
|
|
Debug.Log("pause========true");
|
|
if (WriteTempBefore != null) CrazyAsyKit.StopCoroutine(WriteTempBefore);
|
|
var path = Path.Combine(Application.temporaryCachePath, FolderNames.GameCache);
|
|
if (Directory.Exists(path))
|
|
{
|
|
Debug.Log("shanchu");
|
|
Directory.Delete(path, true); // true 表示递归删除
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("没有文件夹");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
MainThreadDispatcher.Instance.Dispatch(MainThreadMsg.App_Pause_False, pause);
|
|
if (WriteTempBefore == null && MainScene.is_open) WriteTempBefore = CrazyAsyKit.StartCoroutine(TextureHelper.WriteTempBeforeOpenCoroutine_());
|
|
|
|
}
|
|
#endif
|
|
}
|
|
public static Coroutine WriteTempBefore;
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
IsAppQuit = true;
|
|
|
|
CloseApp();
|
|
AppDispatcher.Instance.Dispatch(AppMsg.App_Quit);
|
|
AssetBundle.UnloadAllAssetBundles(true);
|
|
}
|
|
}
|
|
} |