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()); /// /// 客户端当前帧数(非线程安全) 注意: 热重启不会归零 /// public static long FrameCount { get; internal set; } /// /// 主线程ID /// public static readonly int MainThreadId = Thread.CurrentThread.ManagedThreadId; /// /// 根节点 /// 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; } /// /// 启动 /// static public void Start() { _instance?.Start(); } /// /// 关闭 /// /// static public IAsync Close() { AsyncGroup group = new AsyncGroup(); FrameworkSchedulers.RunOnMainThread(() => { var closeAsync = _instance?.Close(); closeAsync?.Join(group); group.End(); }); return group; } /// /// 重启 /// /// static public IAsync Restart() { AsyncGroup group = new AsyncGroup(); FrameworkSchedulers.RunOnMainThread(() => { var restartAsync = _instance?.Restart(); restartAsync?.Join(group); group.End(); }); return group; } /// /// 退出游戏 /// static public void Quit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else UnityEngine.Application.Quit(); #endif } } }