82 lines
2.0 KiB
C#
82 lines
2.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace NBC
|
|
{
|
|
public class App : MonoBehaviour
|
|
{
|
|
public static App Inst { get; private set; }
|
|
|
|
private static Scene _scene;
|
|
public static Scene Main => _scene;
|
|
private static event Action OnInitialized;
|
|
|
|
public static event Action OnUpdate;
|
|
public static event Action OnLateUpdate;
|
|
public static event Action OnFixedUpdate;
|
|
public static event Action OnApplicationQuitAction;
|
|
public static event Action OnApplicationPauseAction;
|
|
|
|
/// <summary>
|
|
/// Scene下的事件系统组件
|
|
/// </summary>
|
|
public static UIComponent UI { get; internal set; }
|
|
|
|
public static void Init(Action callback = null)
|
|
{
|
|
if (Inst != null) return;
|
|
new GameObject("App").AddComponent<App>();
|
|
OnInitialized += callback;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
Inst = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
StartAsync().Coroutine();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
OnUpdate?.Invoke();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
OnLateUpdate?.Invoke();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
OnFixedUpdate?.Invoke();
|
|
}
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
OnApplicationQuitAction?.Invoke();
|
|
}
|
|
|
|
private void OnApplicationPause(bool pauseStatus)
|
|
{
|
|
OnApplicationPauseAction?.Invoke();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_scene?.Dispose();
|
|
}
|
|
|
|
private async FTask StartAsync()
|
|
{
|
|
// 初始化框架
|
|
await NBC.Platform.Unity.Entry.Initialize(GetType().Assembly);
|
|
_scene = await Scene.Create(SceneRuntimeMode.MainThread);
|
|
UI = _scene.AddComponent<UIComponent>();
|
|
OnInitialized?.Invoke();
|
|
}
|
|
}
|
|
} |