提交修改
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public partial 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()
|
||||
{
|
||||
// 初始化框架
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
List<System.Reflection.Assembly> loadAssemblies = new List<System.Reflection.Assembly>();
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
// 跳过系统程序集以提高性能(可选)
|
||||
if (IsSystemAssembly(assembly))
|
||||
continue;
|
||||
loadAssemblies.Add(assembly);
|
||||
}
|
||||
|
||||
await NBC.Platform.Unity.Entry.Initialize(loadAssemblies.ToArray());
|
||||
_scene = await Scene.Create(SceneRuntimeMode.MainThread);
|
||||
UI = _scene.AddComponent<UIComponent>();
|
||||
OnInitialized?.Invoke();
|
||||
}
|
||||
|
||||
// 判断是否是系统程序集(可选优化)
|
||||
private static bool IsSystemAssembly(System.Reflection.Assembly assembly)
|
||||
{
|
||||
string assemblyName = assembly.FullName;
|
||||
return assemblyName.StartsWith("System") ||
|
||||
assemblyName.StartsWith("Microsoft.") ||
|
||||
assemblyName.StartsWith("UnityEngine") ||
|
||||
assemblyName.StartsWith("UnityEditor") ||
|
||||
assemblyName.StartsWith("mscorlib") ||
|
||||
assemblyName.StartsWith("netstandard") ||
|
||||
assemblyName.StartsWith("nunit.") ||
|
||||
assemblyName.StartsWith("Unity.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user