tanghai 2 лет назад
Родитель
Сommit
7238d029ba

+ 6 - 0
DotNet/Directory.Build.props

@@ -0,0 +1,6 @@
+<Project>
+  <PropertyGroup>
+    <LangVersion>11.0</LangVersion>
+    <NoWarn>0169,0649,3021,8981</NoWarn>
+  </PropertyGroup>
+</Project>

+ 2 - 0
DotNet/Loader/Init.cs

@@ -1,5 +1,7 @@
 using System;
+using System.Collections.Generic;
 using CommandLine;
+using MemoryPack;
 
 namespace ET
 {

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

@@ -1,9 +1,9 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <TargetFramework>netstandard2.0</TargetFramework>
+        <TargetFramework>net7.0</TargetFramework>
         <Nullable>disable</Nullable>
-        <LangVersion>9</LangVersion>
+        <LangVersion>10</LangVersion>
         <RootNamespace>ET</RootNamespace>
         <AssemblyName>ThirdParty</AssemblyName>
     </PropertyGroup>
@@ -81,6 +81,7 @@
     <ItemGroup>
       <PackageReference Include="CommandLineParser" Version="2.8.0" />
       <PackageReference Include="EPPlus" Version="5.8.8" />
+      <PackageReference Include="MemoryPack" Version="1.9.13" />
       <PackageReference Include="MongoDB.Driver" Version="2.17.1" />
       <PackageReference Include="NLog" Version="4.7.15" />
       <PackageReference Include="protobuf-net" Version="2.4.6" />

+ 2 - 1
Unity/Assets/Scripts/Codes/Hotfix/Unity.Hotfix.Codes.asmdef

@@ -6,7 +6,8 @@
         "Unity.Core",
         "Unity.Model.Codes",
         "Unity.Mathematics",
-        "Unity.Loader"
+        "Unity.Loader",
+        "MemoryPack"
     ],
     "includePlatforms": [
         "Editor"

+ 92 - 0
Unity/Assets/Scripts/Core/Module/Entity/Scene.cs

@@ -1,7 +1,99 @@
 using System;
+using System.Buffers;
+using System.Collections.Generic;
+using System.IO;
+using MemoryPack;
 
 namespace ET
 {
+    [MemoryPackable]
+    public partial struct Aa
+    {
+        public int A;
+        public int A2;
+    }
+
+    [MemoryPackable]
+    public partial struct Bb
+    {
+        public int B;
+    }
+
+    [MemoryPackable]
+    public partial class Cc
+    {
+        public Aa aaa;
+        
+        public List<Bb> bbb;
+        
+        public Dictionary<long, Bb> ccc;
+    }
+
+    public class FixedArrayBufferWriter: IBufferWriter<byte>
+    {
+        byte[] buffer;
+        int written;
+
+        public FixedArrayBufferWriter(byte[] buffer)
+        {
+            this.buffer = buffer;
+            this.written = 0;
+        }
+
+        public void Reset(byte[] buffer)
+        {
+            this.buffer = buffer;
+            this.written = 0;
+        }
+
+        public void Advance(int count)
+        {
+            this.written += count;
+        }
+
+        public Memory<byte> GetMemory(int sizeHint = 0)
+        {
+            var memory = buffer.AsMemory(written);
+            if (memory.Length >= sizeHint)
+            {
+                return memory;
+            }
+
+            MemoryPackSerializationException.ThrowMessage("Requested invalid sizeHint.");
+            return memory;
+        }
+
+        public Span<byte> GetSpan(int sizeHint = 0)
+        {
+            var span = buffer.AsSpan(written);
+            if (span.Length >= sizeHint)
+            {
+                return span;
+            }
+
+            MemoryPackSerializationException.ThrowMessage("Requested invalid sizeHint.");
+            return span;
+        }
+
+        public byte[] GetFilledBuffer()
+        {
+            if (written != buffer.Length)
+            {
+                MemoryPackSerializationException.ThrowMessage("Not filled buffer.");
+            }
+
+            return buffer;
+        }
+    }
+
+    [MemoryPackable]
+    public partial struct Dd
+    {
+        public int aaa;
+        public string bbb;
+        public List<int> ccc;
+    }
+    
     [EnableMethod]
     [ChildOf]
     public class Scene: Entity, IScene

+ 2 - 1
Unity/Assets/Scripts/Core/Unity.Core.asmdef

@@ -3,7 +3,8 @@
     "rootNamespace": "ET",
     "references": [
         "Unity.ThirdParty",
-        "Unity.Mathematics"
+        "Unity.Mathematics",
+        "MemoryPack"
     ],
     "includePlatforms": [],
     "excludePlatforms": [],

+ 27 - 0
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -1,6 +1,9 @@
 using System;
+using System.Buffers;
+using System.Collections.Generic;
 using System.Threading;
 using CommandLine;
+using MemoryPack;
 using UnityEngine;
 
 namespace ET
@@ -36,10 +39,32 @@ namespace ET
 			ETTask.ExceptionHandler += Log.Error;
 
 			Game.AddSingleton<CodeLoader>().Start();
+			
+			this.cc = new Cc() { aaa = new Aa()};
+			cc.bbb = new List<Bb>();
+			cc.bbb.Add(new Bb() {B = 5});
+			cc.ccc = new Dictionary<long, Bb>();
+			cc.ccc.Add(1, new Bb() {B = 4});
+			fixedArrayBufferWriter = new FixedArrayBufferWriter(this.bytes);
+			//Dd d = new Dd() { aaa = 1, bbb = "ggs" };
+			//d.ccc = new List<int>() { 1, 2, 3 };
+			//bytes = MemoryPackSerializer.Serialize(d);
 		}
 
+		private byte[] bytes = new byte[1024];
+		private Cc cc;
+		private Cc cs = new Cc() {bbb = new List<Bb>(), ccc = new Dictionary<long, Bb>()};
+		private Dd dd;
+
+		private FixedArrayBufferWriter fixedArrayBufferWriter;
+
 		private void Update()
 		{
+			fixedArrayBufferWriter.Reset(this.bytes);
+			MemoryPackSerializer.Serialize(typeof(Cc), fixedArrayBufferWriter, this.cc);
+			MemoryPackSerializer.Deserialize(bytes, ref this.cs);
+			//this.bytes = MemoryPackSerializer.Serialize(this.cc);
+			//MemoryPackSerializer.Deserialize(bytes, ref this.cs);
 			Game.Update();
 		}
 
@@ -54,4 +79,6 @@ namespace ET
 			Game.Close();
 		}
 	}
+	
+	
 }

+ 2 - 1
Unity/Assets/Scripts/Loader/Unity.Loader.asmdef

@@ -4,7 +4,8 @@
     "references": [
         "Unity.ThirdParty",
         "Unity.Core",
-        "HybridCLR.Runtime"
+        "HybridCLR.Runtime",
+        "MemoryPack"
     ],
     "includePlatforms": [],
     "excludePlatforms": [],

+ 1 - 1
Unity/Directory.Build.props

@@ -1,6 +1,6 @@
 <Project>
   <PropertyGroup>
-    <LangVersion>10.0</LangVersion>
+    <LangVersion>11.0</LangVersion>
     <NoWarn>0169,0649,3021</NoWarn>
   </PropertyGroup>
 </Project>

+ 2 - 1
Unity/Packages/manifest.json

@@ -1,7 +1,8 @@
 {
   "dependencies": {
+    "com.cysharp.memorypack": "https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack",
     "com.focus-creative-games.hybridclr_unity": "https://gitee.com/focus-creative-games/hybridclr_unity.git",
-    "com.unity.ide.rider": "3.0.17",
+    "com.unity.ide.rider": "3.0.21",
     "com.unity.ide.visualstudio": "2.0.17",
     "com.unity.ide.vscode": "1.2.5",
     "com.unity.render-pipelines.universal": "12.1.8",

+ 8 - 1
Unity/Packages/packages-lock.json

@@ -1,5 +1,12 @@
 {
   "dependencies": {
+    "com.cysharp.memorypack": {
+      "version": "https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack",
+      "depth": 0,
+      "source": "git",
+      "dependencies": {},
+      "hash": "09eb5f1535d0d01dee98c84fa110c21a436bd896"
+    },
     "com.focus-creative-games.hybridclr_unity": {
       "version": "https://gitee.com/focus-creative-games/hybridclr_unity.git",
       "depth": 0,
@@ -24,7 +31,7 @@
       "url": "https://packages.unity.com"
     },
     "com.unity.ide.rider": {
-      "version": "3.0.17",
+      "version": "3.0.21",
       "depth": 0,
       "source": "registry",
       "dependencies": {