123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System.Threading;
- using UnityEngine;
- using XGame.Framework.Asyncs;
- using XGame.Framework.ThreadScheduler;
- namespace XGame.Framework
- {
- public partial class AppManager
- {
- private static IAppManager _instance;
- private static IAppManager Instance => _instance ?? (_instance = new AppManager());
- /// <summary>
- /// 客户端当前帧数(非线程安全) 注意: 热重启不会归零
- /// </summary>
- public static long FrameCount { get; internal set; }
- /// <summary>
- /// 主线程ID
- /// </summary>
- public static readonly int MainThreadId = Thread.CurrentThread.ManagedThreadId;
- /// <summary>
- /// 根节点
- /// </summary>
- public static Transform Root => _instance?.Root;
- internal static string GameLogicTypeName;
- internal static bool IsSessionDebug;
- internal static void Initialize()
- {
- Instance.Restart();
- }
- internal static void Dispose()
- {
- _instance = null;
- }
- /// <summary>
- /// 启动
- /// </summary>
- static public void Start()
- {
- _instance?.Start();
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <returns></returns>
- static public IAsync Close()
- {
- AsyncGroup group = new AsyncGroup();
- FrameworkSchedulers.RunOnMainThread(() =>
- {
- var closeAsync = _instance?.Close();
- closeAsync?.Join(group);
- group.End();
- });
- return group;
- }
- /// <summary>
- /// 重启
- /// </summary>
- /// <returns></returns>
- static public IAsync Restart()
- {
- AsyncGroup group = new AsyncGroup();
- FrameworkSchedulers.RunOnMainThread(() =>
- {
- var restartAsync = _instance?.Restart();
- restartAsync?.Join(group);
- group.End();
- });
- return group;
- }
- /// <summary>
- /// 退出游戏
- /// </summary>
- static public void Quit()
- {
- #if UNITY_EDITOR
- UnityEditor.EditorApplication.isPlaying = false;
- #else
- UnityEngine.Application.Quit();
- #endif
- }
- }
- }
|