using System; using System.Buffers; using System.Collections.Generic; using System.Threading; using CommandLine; using MemoryPack; using UnityEngine; namespace ET { public class Init: MonoBehaviour { private void Start() { DontDestroyOnLoad(gameObject); AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; Game.AddSingleton(); // 命令行参数 string[] args = "".Split(" "); Parser.Default.ParseArguments(args) .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}")) .WithParsed(Game.AddSingleton); Options.Instance.StartConfig = "StartConfig/LockStep"; Game.AddSingleton(); Game.AddSingleton().ILog = new UnityLogger(); Game.AddSingleton(); Game.AddSingleton(); Game.AddSingleton(); Game.AddSingleton(); Game.AddSingleton(); ETTask.ExceptionHandler += Log.Error; Game.AddSingleton().Start(); this.cc = new Cc() { aaa = new Aa()}; cc.bbb = new List(); cc.bbb.Add(new Bb() {B = 5}); cc.ccc = new Dictionary(); 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() { 1, 2, 3 }; //bytes = MemoryPackSerializer.Serialize(d); } private byte[] bytes = new byte[1024]; private Cc cc; private Cc cs = new Cc() {bbb = new List(), ccc = new Dictionary()}; 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(); } private void LateUpdate() { Game.LateUpdate(); Game.FrameFinishUpdate(); } private void OnApplicationQuit() { Game.Close(); } } }