结构大修改,改成朴实无华的结构,不过度架构。能跑就行
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using NBF.Fishing2;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,27 +11,104 @@ namespace NBF
|
||||
{
|
||||
public static Game Instance { get; private set; }
|
||||
|
||||
public static InputComponent Input;
|
||||
|
||||
/// <summary>
|
||||
/// 主摄像机
|
||||
/// </summary>
|
||||
public static Camera MainCamera { 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>
|
||||
/// 摄像机配置
|
||||
/// </summary>
|
||||
// public static CameraScriptObject CameraConfig { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自身的unit id
|
||||
/// </summary>
|
||||
public static long SelfId;
|
||||
|
||||
public static void SetInitCallback(GameObject root, Action callback = null)
|
||||
{
|
||||
if (Instance != null) return;
|
||||
root.AddComponent<Game>();
|
||||
OnInitialized += callback;
|
||||
// NBC_Fantasy_EntitySystemRegistrar
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
// CameraConfig = Resources.Load<CameraScriptObject>(nameof(CameraConfig));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 1. 初始化 Fantasy 框架
|
||||
await Fantasy.Platform.Unity.Entry.Initialize();
|
||||
|
||||
// 2. 创建一个 Scene (客户端场景)
|
||||
// Scene 是 Fantasy 框架的核心容器,所有功能都在 Scene 下运行
|
||||
// SceneRuntimeMode.MainThread 表示在 Unity 主线程运行
|
||||
_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