Просмотр исходного кода

增加Entry,DotNet用这个初始化

tanghai 3 лет назад
Родитель
Сommit
a04455a6d2

+ 47 - 0
Codes/Model/Server/Entry.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using CommandLine;
+using NLog;
+
+namespace ET.Server
+{
+    public static class Entry
+    {
+        public static void Start()
+        {
+            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
+            {
+                Log.Error(e.ExceptionObject.ToString());
+            };
+			
+            ETTask.ExceptionHandler += Log.Error;
+
+            // 异步方法全部会回掉到主线程
+            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
+            
+            Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof(Game).Assembly, typeof(Entry).Assembly, DllHelper.GetHotfixAssembly());
+                    
+            Game.EventSystem.Add(types);
+				
+            MongoHelper.Register(Game.EventSystem.GetTypes());
+
+            string[] args = System.Environment.GetCommandLineArgs();
+            
+            // 命令行参数
+            Options options = null;
+            Parser.Default.ParseArguments<Options>(args)
+                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
+                .WithParsed(o => { options = o; });
+
+            Options.Instance = options;
+
+            Game.ILog = new NLogger(Game.Options.AppType.ToString());
+            LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
+				
+            Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
+
+            Game.EventSystem.Publish(Game.Scene, new ET.EventType.AppStart());
+        }
+    }
+}

+ 14 - 0
Codes/ModelView/Client/Entry.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Threading;
 
 namespace ET.Client
 {
@@ -8,11 +9,24 @@ namespace ET.Client
 		{
 			try
 			{
+				System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
+				{
+					Log.Error(e.ExceptionObject.ToString());
+				};
+				
+				SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
+				
 				CodeLoader.Instance.Update += Game.Update;
 				CodeLoader.Instance.LateUpdate += Game.LateUpdate;
 				CodeLoader.Instance.OnApplicationQuit += Game.Close;
 				
 				MongoHelper.Register(Game.EventSystem.GetTypes());
+				
+				Game.ILog = new UnityLogger();
+				
+				ETTask.ExceptionHandler += Log.Error;
+
+				Options.Instance = new Options();
 
 				Game.EventSystem.Publish(Game.Scene, new EventType.AppStart());
 			}

+ 2 - 34
DotNet/App/Program.cs

@@ -1,8 +1,6 @@
 using System;
-using System.Collections.Generic;
 using System.Threading;
-using CommandLine;
-using NLog;
+using ET.Server;
 
 namespace ET
 {
@@ -10,39 +8,9 @@ namespace ET
 	{
 		private static void Main(string[] args)
 		{
-			AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
-			{
-				Log.Error(e.ExceptionObject.ToString());
-			};
-			
-			ETTask.ExceptionHandler += Log.Error;
-
-			// 异步方法全部会回掉到主线程
-			SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
-			
 			try
 			{	
-				Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Unit).Assembly, DllHelper.GetHotfixAssembly());
-                    
-				Game.EventSystem.Add(types);
-				
-				ProtobufHelper.Init();
-				MongoHelper.Register(Game.EventSystem.GetTypes());
-				
-				// 命令行参数
-				Options options = null;
-				Parser.Default.ParseArguments<Options>(args)
-						.WithNotParsed(error => throw new Exception($"命令行格式错误!"))
-						.WithParsed(o => { options = o; });
-
-				Options.Instance = options;
-
-				Game.ILog = new NLogger(Game.Options.AppType.ToString());
-				LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
-				
-				Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
-
-				Game.EventSystem.Publish(Game.Scene, new EventType.AppStart());
+				Entry.Start();
 				
 				while (true)
 				{

+ 2 - 2
DotNet/ThirdParty/DotNet.ThirdParty.csproj

@@ -1,9 +1,9 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <TargetFramework>net6.0</TargetFramework>
+        <TargetFramework>netstandard2.0</TargetFramework>
         <Nullable>disable</Nullable>
-        <LangVersion>10</LangVersion>
+        <LangVersion>9</LangVersion>
         <RootNamespace>ET</RootNamespace>
         <AssemblyName>ThirdParty</AssemblyName>
     </PropertyGroup>

+ 0 - 1
DotNet/Tool/Program.cs

@@ -26,7 +26,6 @@ namespace ET.Server
                     
                 Game.EventSystem.Add(types);
                 
-                ProtobufHelper.Init();
                 MongoHelper.Register(Game.EventSystem.GetTypes());
 				
                 // 命令行参数

+ 1 - 5
Unity/Assets/Scripts/Core/ProtobufHelper.cs

@@ -7,11 +7,7 @@ namespace ET
 {
     public static class ProtobufHelper
     {
-	    public static void Init()
-        {
-        }
-
-        public static object FromBytes(Type type, byte[] bytes, int index, int count)
+		public static object FromBytes(Type type, byte[] bytes, int index, int count)
         {
 	        using (MemoryStream stream = new MemoryStream(bytes, index, count))
 	        {

+ 1 - 14
Unity/Assets/Scripts/Mono/MonoBehaviour/Init.cs

@@ -19,21 +19,8 @@ namespace ET
 #if ENABLE_IL2CPP
 			this.CodeMode = CodeMode.ILRuntime;
 #endif
-			
-			System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
-			{
-				Log.Error(e.ExceptionObject.ToString());
-			};
-			
-			SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
-			
-			DontDestroyOnLoad(gameObject);
-
-			ETTask.ExceptionHandler += Log.Error;
 
-			Game.ILog = new UnityLogger();
-
-			Options.Instance = new Options();
+			DontDestroyOnLoad(gameObject);
 
 			CodeLoader.Instance.CodeMode = this.CodeMode;
 		}