mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] TEngineServer
[+] TEngineServer
This commit is contained in:
36
Assets/GameScripts/DotNet/Core/Unity/ApplicationContext.cs
Normal file
36
Assets/GameScripts/DotNet/Core/Unity/ApplicationContext.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
#if TENGINE_UNITY
|
||||
using System.Threading;
|
||||
using TEngine.Core;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public struct OnAppStart
|
||||
{
|
||||
public Scene ClientScene;
|
||||
}
|
||||
|
||||
public struct OnAppClosed { }
|
||||
|
||||
public static class ApplicationContext
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
// 设置默认的线程的同步上下文
|
||||
SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Main);
|
||||
// 初始化SingletonSystemCenter这个一定要放到最前面
|
||||
// 因为SingletonSystem会注册AssemblyManager的OnLoadAssemblyEvent和OnUnLoadAssemblyEvent的事件
|
||||
// 如果不这样、会无法把程序集的单例注册到SingletonManager中
|
||||
SingletonSystem.Initialize();
|
||||
// 加载核心程序集
|
||||
AssemblyManager.Initialize();
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
SingletonSystem.Dispose();
|
||||
AssemblyManager.Dispose();
|
||||
Scene.DisposeAllScene();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7db9c21fafd32054580caf1503ba2f17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/GameScripts/DotNet/Core/Unity/AssemblyName.cs
Normal file
16
Assets/GameScripts/DotNet/Core/Unity/AssemblyName.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
public static class AssemblyName
|
||||
{
|
||||
// 这个对应的是NetCore工程
|
||||
public const int AssemblyDotNet = 1;
|
||||
|
||||
public const int GameBase = 10;
|
||||
|
||||
public const int GameLogic = 20;
|
||||
|
||||
public const int GameProto = 30;
|
||||
|
||||
// 你可以添加多个工程、如果有新添加的可以在这里添加、
|
||||
// 并在AssemblyLoadHelper里添加对应的加载逻辑
|
||||
// 参考LoadModelDll这个方法
|
||||
// 这样添加是为了方便后面热重载使用
|
||||
}
|
11
Assets/GameScripts/DotNet/Core/Unity/AssemblyName.cs.meta
Normal file
11
Assets/GameScripts/DotNet/Core/Unity/AssemblyName.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44af1c6e3b8a24b40a198c068993596d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/GameScripts/DotNet/Core/Unity/GameAppEntry.cs
Normal file
40
Assets/GameScripts/DotNet/Core/Unity/GameAppEntry.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#if TENGINE_UNITY
|
||||
using TEngine.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class GameAppEntry : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化框架
|
||||
/// </summary>
|
||||
public static Scene Initialize()
|
||||
{
|
||||
// 初始化框架
|
||||
ApplicationContext.Initialize();
|
||||
new GameObject("[TEngine.Unity]").AddComponent<GameAppEntry>();
|
||||
// 框架需要一个Scene来驱动、所以要创建一个Scene、后面所有的框架都会在这个Scene下
|
||||
// 也就是把这个Scene给卸载掉、框架的东西都会清除掉
|
||||
return Scene.Create("Unity");
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
ThreadSynchronizationContext.Main.Update();
|
||||
SingletonSystem.Update();
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
EventSystem.Instance?.Publish(new OnAppClosed());
|
||||
ApplicationContext.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/GameScripts/DotNet/Core/Unity/GameAppEntry.cs.meta
Normal file
11
Assets/GameScripts/DotNet/Core/Unity/GameAppEntry.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcb9cd4fe550bbe4083cc7c54ae9c0ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user